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
Re: [VB.Net] A Few database related questions 80 80

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

Re: [VB.Net] A Few database related questions 80 80

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

Re: [VB.Net] A Few database related questions 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.