Click here to Skip to main content
15,851,319 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have a table in sql database named user. i try to retrieve data in that table. but when i use textbox, only one data retrieved. so i would like to retrieve the data in a html table so that the data would be in a list. iam using vb.net and visual studio 2003

What I have tried:

VB
Dim cnConnect As New SqlConnection
        cnConnect.ConnectionString = conn.ConnectionString
        cnConnect.Open()
        Dim cm As New SqlCommand
        cm.CommandText = "SELECT * FROM user "
        Dim connection As New SqlConnection(conn.ConnectionString)
        Dim dataadapter As New SqlDataAdapter(cm.CommandText, connection)
        Dim ds As New DataSet
        connection.Open()
        dataadapter.Fill(ds, "user")
        connection.Close()
        DataGrid1.DataSource = ds
        DataGrid1.DataMember = "user"
        cnConnect.Close()
Posted
Updated 25-Sep-16 22:05pm
v2

1 solution

Multiple SqlConnection not required.
Try this -
VB
Dim cnConnect As New SqlConnection
        cnConnect.ConnectionString = conn.ConnectionString
        cnConnect.Open()
        Dim cm As New SqlCommand
        cm.CommandText = "SELECT * FROM user";
        Dim dataadapter As New SqlDataAdapter(cm.CommandText, cnConnect)
        Dim ds As New DataSet
        dataadapter.Fill(ds, "user")
        DataGrid1.DataSource = ds
        DataGrid1.DataMember = "user";
        cnConnect.Close()

Reference: Bind / Fill / Populate DataGridView with DataSet in Windows Forms (WinForms) Application in C# and VB.Net[^]

Hope, it helps :)
 
Share this answer
 
Comments
Member 12759272 26-Sep-16 3:33am    
i have tried your code. still the data are not retrieved
Suvendu Shekhar Giri 26-Sep-16 3:44am    
Can you please put a breakpoint in the following line -
DataGrid1.DataMember = "user";
and see if "ds" is getting filled with data or not?
Member 12759272 26-Sep-16 5:44am    
still do not works
Suvendu Shekhar Giri 26-Sep-16 6:15am    
What is not working?
What are your findings over debugging?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900