Click here to Skip to main content
16,023,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone

I should get the code to populate table data in grid. later i should also be in position to edit and save. the following code i am using to get data from the table but it is not working

VB
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myconnection As New SqlConnection("server=THEJASVI-PC\SQLEXPRESS;database=emp;uid=sa;pwd=2x12")
        myconnection.Open()
        ds = New DataSet()
        s = "select * from emp_details"

        Dim da As New SqlDataAdapter(s, myconnection)

        da.Fill(ds, "emp_details")
        dgvEmployeedetails.DataSource = ds.DefaultViewManager


    End Sub


so help me kindly to correct my code
Posted
Updated 28-Jul-10 21:41pm
v4

You missed to associate SQL Command to the adapter.

Have a look here of how to use DataAdapter to fill dataset:
SqlDataAdapter Class[^]
 
Share this answer
 
dgvEmployeedetails.DataSource = ds.DefaultViewManager


I would change this to


dgvEmployeedetails.DataSource = ds.tables(0)


The example you've shown will work, but the link that sandeep has posted is the better solution to use, more maintainable
 
Share this answer
 
Comments
parchuri08 29-Jul-10 10:04am    
Thanks a lot Simon_Whale your code really worked.

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