Hi All,

I want to know how to bind data to DataGridView Control.
I have seen examples on google nd other sites. but all examples use DataBind() while in my program, it shows DataBindings() in intellisense. I cant find out how to do this. I have to bind data from Sql Database Table.

Hope my problem is clear.


There are many ways to bind data to the DataGridView. The method i use is
1. Create columns in the DataGridView control.
2. Create DataTable with the same columns.
3. Create Rows for the Datatable and insert data in to the row.
4. Set DataSource property of the DataGridview control to the created table.
5. Call DataBind method.

I think DataBinding is a property not a method.

commented: Very good +5

tht's wht my problem is.. When I call DataBind Method it shows error stating : 'DataBind' is not a member of 'System.Windows.Forms.DataGridView'.
This I am not able to resolve.

Dim con As SqlConnection
        Dim sql As String = ""
        Dim cmd As SqlCommand
        con = ("server=....")
        sql = "SELECT * FROM MYTABLE"

        cmd = New SqlCommand(sql, con)
            gridview.DataSource = cmd.ExecuteReader
            gridview.DataBind() ' Here it shows the Error


        Catch ex As Exception
        End Try

So, do not use DataBind() method. Please follows all steps of thread #2 - lighthead except 5th.

DataBind() is method of ASP.NET server control.

Hello sir,
What Shall I use instead of DataBind() then.
I did what lighthead suggested. But I am still not able to show the data from database to the datagridview. It does not show any errors now, but am not able to get the data also.


  Dim adp as new SqlDataAdpater("select * from table",cn)
  Dim dt as new DataTable


its a web application or forms..
if it is forms, it is enough if u give DataSource.

Now, I am able to do it.



Mark this thread as solved if you get solution.