I'm developing an application for my psing SQL Server 2005 as database and VB.Net 2008. Ive created the form and successfully connected all text boxes etc. Using the code, I have managed to open the database and fill the dataset. However when i BIND the Datagrid datasource to the Dataset, I can only see the COLUMN NAMES in the datagrid and not the rows or the data. Can someone please analyze my code and tell me whats wrong?

Also I'd be really grateful if you guys could tell me how to Insert, Update and Delete data.

I'm fairly new to VB.Net but I have used VB6 before

Thanks in advance


Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click

        Dim con As New OleDb.OleDbConnection
        Dim dbprovider As String
        Dim dbsource As String
        Dim ds As New DataSet
        Dim da As New OleDb.OleDbDataAdapter
        Dim sql As String

        dbprovider = "Provider=SQLOLEDB;Integrated Security=SSPI;"
        dbsource = "Data Source=THOR\SQLEXPRESS"
        con.ConnectionString = dbprovider & dbsource

        sql = "SELECT [Company Name],[Representative Name],[Street],[City],[State],[Zip Code],[Country],[Phone],[Fax],[Mobile],[Email],[Notes]  FROM [Project].[dbo].[customer]"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "AddressBook")

        MsgBox("Database is now open")
        MsgBox("Database is now Closed")

        DataGridView1.DataSource = ds

    End Sub

Recommended Answers

All 3 Replies

Try to add a DataGridView1.Refresh() after setting the datasource. Aassuming that the table "AddressBook" has some rows, this will ensure that the contents of the data grid view is fully reloaded an repainted.

Hope this helps

I tried that before but it dint help.

Later what I did was instead of using :

da.Fill(ds, "AddressBook")

I used :

Dim dt As New DataTable



and changed the grid source to dt like this :

DataGridView1.DataSource = dt

With this, I can get all the data in the datagrid perfectly...but is this the right way to do it?

Also, can someone please show me how to code for inserting, updating and deleting data in the table?

Thank You

you also have to use datagridview datamember property


Best Of Luck

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.