Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim table As New DataTable
constructor
initialze the cn object like eg
cn new sqlconnection( server name;database name;uid name;pwd name; )
write it in the button .click event that add the table dynamicaaly created to datagrid
Try
cmd New SqlCommand
cmd.CommandType CommandType.Text
cmd.Connection cn
cmd.CommandText select * from manas
cn.Open()
dr cmd.ExecuteReader()
Dim i As Integer
For i 0 To dr.FieldCount - 1
table.Columns.Add(i)
Next
Dim row As DataRow
While dr.Read()
row table.NewRow()
For i 0 To dr.FieldCount - 1
row(i) dr(i)
Next
table.Rows.Add(row)
End While
DataGrid1.DataSource table
Catch ex As Exception
MsgBox(ex.Message & ex.StackTrace)
Finally
cn.Close()
dr.Close()
End Try