0

I am trying to use a VB generated textbox to display the values/names, that are within an SQL database. I started with VB and SQL last week; I tried to use a self-built method named GetUserInfo() to display the values, but it doesnt display anything.

This is the segment used for the Textbox in VB

Public Class user_selection_screen
Private SQL As SQLControl
Private Authuser As String

Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles box_user_selection.SelectedIndexChanged
  GetUserInfo()
End Sub

Public Sub GetUserInfo()
  SQL.RunQuery("SELECT Name" & "FROM" ""User"")

  For Each i As Object In SQL.SQLDS.Tables(0).Rows
    box_user_selection.Text = i.Item("Name" & vbCrLf)
  Next
End Sub

I started learning VB and SQL last week, so please keep the explanations as simple as possible.

4
  • What's the schema for table User? Commented Aug 15, 2014 at 7:59
  • you mean how the table user is set up in SQL? Currently it has 8 columns, and 2 rows. We created two users, Max and admin; Max is a student type with restricted rights, while admin is an admin user type Commented Aug 15, 2014 at 8:13
  • box_user_selection.Text = i.Item("Name" & vbCrLf), aren't you replacing the text over with each loop? Commented Aug 15, 2014 at 8:30
  • I thought I can add the columns after another with this, to get the table-look Commented Aug 15, 2014 at 9:57

2 Answers 2

0

When you run SQL.RunQuery("SELECT Name" & "FROM" ""User"")

are you sure it fills the DS SQL.SQLDS.Tables(0).Rows?

If yes then,

Dim StrVal As String
For i = 0 To SQL.SQLDS.Tables(0).Rows.Count - 1
    StrVal = StrVal & SQL.SQLDS.Tables(0).Rows(i).Item("Name").ToString()
Next i

box_user_selection.Text = StrVal

To see if your SQLDS.Table really returns a row, Msgbox(SQL.SQLDS.Tables(0).Rows.Count)

Sign up to request clarification or add additional context in comments.

Comments

0

Make sure your SQLDS Has value. If your SQLDS is Dataset, Loop through your SQLDS table by datarow. see example

    For Each dr As DataRow In SqlDs.Tables(0).Rows
        box_user_selection.Text = Convert.ToString(dr("Name"))
    Next

2 Comments

I fail to understand what you mean? SQLDS means datasource, or dataset, right? which means I need to make sure the SQL table is filled with values, which it is. I also gt that I have to loop through each row and get the values, but I am unsure of how to actually get these values, and then display them in an appropriate textbox row
yes SQLDS is dataset. Try looping using For Each loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.