I spent half a day yesterday trying to figure that out. I'm glad it's simple.
"William (Bill) Vaughn" wrote:
> Add a DataGridView control to the form.
> Once the DataTable is created code:
>
> DataGridView1.DataSource = MyTable
>
> There are lots of better examples in my book.
>
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> INETA Speaker
>
www.betav.com/blog/billva >
www.betav.com > Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no rights.
> __________________________________
> Visit
www.hitchhikerguides.net to get more information on my latest book:
> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
> -----------------------------------------------------------------------------------------------------------------------
>
> "BillyRogers" <BillyRogers@discussions.microsoft.com> wrote in message
> news:1DEF8473-2F97-4189-A0E8-2DDBCA4F59C6@microsoft.com...
> > 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
>
>