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.
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.
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
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.