Hey Guys,


I Want to Display Content of Database Into TextBox,
i.e.

i have column named "Ename" in "EMP" table of database1 ,

now i want to display "Ename" in TextBox of my form ,

so, how can i do this ?


Thanks In Advance

Recommended Answers

All 11 Replies

What is your code for this? Please post ur code and the problem with the code.

i haven't written any code yet..
i just want to know how can i retrieve my table data into textbox

So you want to display one one item? If one, which one? If more, you better use Listobx control.

yes
i want to display one one item
i have employee details form,
each textbox should be filled from database

and i also want to use BINDING NAVIGATOR

write the Stored procedure in ur DB for selecting the records from DB and get those details in dataset, loop through dataset and assign to textbox accordingly.

ok i got it
now just tell me code for assigning value from dataset to textbox

For i As Integer = 0 To DataGridView1.Rows.Count - 1
                TextBox1.Text = DataGridView1.Rows.Item("Pass index or Columnname").ToString
            Next

look, i wrote this code
but i cant get the result

Try

            cn.Open()
            Dim da1 As New SqlDataAdapter
            Dim ds As New DataSet

            da1 = New SqlDataAdapter("select * from  Employee_Master", cn)
            da1.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)

            TextBox2_name.Text = DataGridView1.Rows.Item("2").ToString

        Catch ex As Exception
            MessageBox.Show(ex.ToString())

        Finally
            cn.Close()
        End Try

If you are using the second field in the row to fill the textbox then you can:

TextBox2_name.Text = DataGridView1.Rows.Item(2).ToString

Hope this helps

nop its isn't working

its giving output as " DataGridViewRow { Index=2 } "

can you please give me the complete code for this thing ?

Try

            Dim cn As SqlConnection
            Dim strCnn As String = "Your data base connection string"
            cn = New SqlConnection(strCnn)
            cn.Open()
            Dim comm As New SqlCommand("select * from  Employee_Master", cn)
            comm.CommandType = CommandType.Text

            Dim ds As SqlDataReader
            ds = comm.ExecuteScalar
            If ds.HasRows Then
                While ds.Read
                    ''
                    ' do what u want here using the data
                    TextBox2_name.Text = ds.Item(2)
                End While
            End If

            cn.Close()

        Catch ex As Exception
            MessageBox.Show(ex.ToString())

        Finally

        End Try
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.