G
Guest
I'm using VBExpress and SQL Server 2000 which means that I can't use the
wizards/database explorer to do this stuff. It has to be done in code.
I've figured out how to connect to the database and execute a query, but so
for I've Only been able to put the results into a messagebox. I want to put
the results in a DataGridView but don't know how. I can't use the
Databindings wizard in the property window for the datagridview. I'm sure
there must be someway to do the same thing through code.
thanks in advance for any help.
Billy
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim strConn, strSQL As String
strConn = "data source=ServerName;" & _
"database=DBNAme;Trusted_Connection=yes;"
strSQL = "SELECT top " & TextBox1.Text & " * from [tbl_Name]"
Using cn As New SqlConnection(strConn)
Try
cn.Open()
Catch ex As Exception
MessageBox.Show("Connect Attempt Failed")
MessageBox.Show(ex.Message.ToString)
End Try
Dim tbl As DataTable = cn.GetSchema("Tables")
For Each row As DataRow In tbl.Rows
MessageBox.Show(row("Table_Name"))
Next row
cn.Close()
End Using
End Sub
--
Billy Rogers
Dallas,TX
Currently Using SQL Server 2000, Office 2000 and Office 2003 and VBExpress
wizards/database explorer to do this stuff. It has to be done in code.
I've figured out how to connect to the database and execute a query, but so
for I've Only been able to put the results into a messagebox. I want to put
the results in a DataGridView but don't know how. I can't use the
Databindings wizard in the property window for the datagridview. I'm sure
there must be someway to do the same thing through code.
thanks in advance for any help.
Billy
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim strConn, strSQL As String
strConn = "data source=ServerName;" & _
"database=DBNAme;Trusted_Connection=yes;"
strSQL = "SELECT top " & TextBox1.Text & " * from [tbl_Name]"
Using cn As New SqlConnection(strConn)
Try
cn.Open()
Catch ex As Exception
MessageBox.Show("Connect Attempt Failed")
MessageBox.Show(ex.Message.ToString)
End Try
Dim tbl As DataTable = cn.GetSchema("Tables")
For Each row As DataRow In tbl.Rows
MessageBox.Show(row("Table_Name"))
Next row
cn.Close()
End Using
End Sub
--
Billy Rogers
Dallas,TX
Currently Using SQL Server 2000, Office 2000 and Office 2003 and VBExpress