0

This is my code for displaying records from database to combo box but, when I edit the code and make it for textbox, .DataSource and .ValueMember are not working for textboxes.

 Dim sqlconn As New SqlClient.SqlConnection
    sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
    "Database = EOEMS;integrated security=true"

    Dim dt As New DataTable

    sqlconn.Open()
    Dim da As New SqlDataAdapter("SELECT * FROM tblOfficeEquipmentProfile", sqlconn)
    da.Fill(dt)
    cmbLocationCode.DataSource = dt
    cmbLocationCode.ValueMember = "OE_ID"
    sqlconn.Close()

What is the corresponding code for displaying data from database using textboxes?

4
  • Exactly the same code. You just need to extract the data from the "da" datatable and put it into a text box. Commented Apr 8, 2013 at 8:16
  • using textboxes? m mean to say u need to fetch data from database and diplay it in a textbox? Commented Apr 8, 2013 at 8:17
  • @PraveenNambiar yes sir fetching data from database and display it to the textbox Commented Apr 8, 2013 at 8:27
  • @CathalMF i tried editing the code for comboboxes but .datasource and .valuemember are not for textboxes, only works for comboboxes Commented Apr 8, 2013 at 8:27

3 Answers 3

2

You can simple do this:

yourTextBox.Text = dt.Rows(0)("ColumnName").ToString()
Sign up to request clarification or add additional context in comments.

1 Comment

i just used this code Dim da As New SqlDataAdapter("SELECT * FROM tblOfficeEquipmentProfile", sqlconn) da.Fill(dt) txtName.Text = dt.Rows(0)("OE_Name").ToString()
0

it does not diplay data sir

 Public Sub PopulateOeqProfileForm()
    Dim sqlconn As New SqlClient.SqlConnection
    sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
    "Database = EOEMS;integrated security=true"

    Dim dt As New DataTable

    sqlconn.Open()
    Dim da As New SqlDataAdapter("SELECT * FROM tblOfficeEquipmentProfile", sqlconn)
    da.Fill(dt)
    txtOEID.Text = dt.Rows(0)("OE_ID").ToString()
    sqlconn.Close()
End Sub

3 Comments

what do you mean how much is the row count?
Meaning : When you are filling it in the Datatable what is the row count. dt.Rows.count..
Check whether OE_ID for row 1 has values or not. Or is it just Empty or null
0

There is no property like datasource,valuemember and display name will not availiable. please refer this link.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox_properties(v=vs.90).aspx

You only able to assign values from database or local assigment. You should do in the following ways . Assume that if you have txtUserName textbox , you should assign the follwing way

txtLocationCode=dt.rows[0]["column name"].tostring()

There is no property datasource is not availiable since it not collection object. It holds only one column value from database.

Update :

Public Sub PopulateOeqProfileForm()
Dim sqlconn As New SqlClient.SqlConnection
    sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
   "Database = EOEMS;integrated security=true"

    Dim dt As New DataTable

    sqlconn.Open()

     Dim SelectCommand As New SqlClient.SqlCommand (SELECT OE_ID FROM tblOfficeEquipmentProfile, sqlconn)

   txtOEID.Text = Cstr(SelectCommand.ExecuteScalar()) 
   sqlconn.Close() 
End Sub

Hope this helps

5 Comments

id revised my code for the corresponding column and tables names kindly check sir
you want to store only one column value or multiple column values
Then you can use excutescalar function instead of SqlDataAdapter. I will edit post to scalar function. Since usage of datatable will costs performance.
Please check my answer i have revised the answer
please remove line the da.fill(dt) and then try

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.