nhaas

Ok for a while now I have been populating a DataGridViews via Queries from SQL.

Now I would like to populate some text boxes VIA SQL how to do I do this,

Queries that I use

My Query that goes into a DataGridView:

Dim connectionString = "Data Source=ISISQL;Initial Catalog=Testdev;Integrated Security=True"

Dim theDataSet As New DataSet()

Dim theSqlCommand As New SqlCommand("Select BU,name from TESIS2 WHERE [bldg] LIKE '%" & Me.ComboBox2.Text & "%'", New SqlConnection(connectionString))

Dim theDataAdapter As New SqlDataAdapter(theSqlCommand)

theDataAdapter.Fill(theDataSet)

theSqlCommand.Connection.Close()

Me.TesisView1.DataSource = theDataSet.Tables(0).DefaultView

am not sure where to start, I know that I need a loop and stuff in there. thank you




Re: Visual Basic Express Edition populate testbox from SQL query

nhaas

OK I found some old code that I used in ACCESS but i cannot convert it to SQL.

A little guidance please.

Dim connectionString = "Data Source=ISISQL;Initial Catalog=Testdev;Integrated Security=True"

Dim theSqlCommand As New SqlCommand("Select BU,name from TESIS2 ", New SqlConnection(connectionString))

Using theSqlCommand As New OleDb.OleDbConnection(connectionString)

Dim command As New OleDb.OleDbCommand(theSqlCommand, connectionString)

connectionString.Open()

Dim reader As OleDb.OleDbDataReader = command.ExecuteReader()

While reader.Read()

Me.TextBox1.Text = reader.GetInt32(0).ToString()

Me.TextBox2.Text = reader.GetString(1)

End While

' always call Close when done reading.

reader.Close()

End Using

i am having some troubles with "the SQLCommand" right now.






Re: Visual Basic Express Edition populate testbox from SQL query

Riquel Dong ĘC MSFT

Hi Nhaas,

Why do you populate the TextBox control like this way If you need to use the TextBox control to display the data from the database, I recommend that you fetch the data into the dataset object and you can bind the one datacolumn to the Text property of the TextBox control. I think this should satisfy your requirements better. Please try this method. If you have any further questions, please tell me.

Best regards.







Re: Visual Basic Express Edition populate testbox from SQL query

nhaas

I do this because I can connect to the Database easier. were I work they will not add the .net fram work stuff do the network SQL server.

it makes it kind of harder to bind everything.

let me know if I am wrong.






Re: Visual Basic Express Edition populate testbox from SQL query

Riquel Dong ĘC MSFT

Hi Nhaas,

Could you clarify your scenario What do you mean " were I work they will not add the .net fram work stuff do the network SQL server. it makes it kind of harder to bind everything". Based on my experience, there is no mechanism in the .NET class libraries to accommodate binding of data directly to a database. So I recommend you ought to use the data binding to use the textbox.

Best regards.






Re: Visual Basic Express Edition populate testbox from SQL query

js06

You can cheat on this one

When you navigate throught the records you can use the currentrow property and get the index of the cell (column) that you want. Then show the value as the textbox text