fill datagridview from sql

M

mcnews

how to fill a datagridview control using a sql statement that joins 3
tables?

tia,
mcnewsxp
 
M

mcnews

using SQL:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim connectionString As String = "Data Source=MyServer;Initial
Catalog=MyDB;UID=MyUID;pwd=MyPWD"
Dim sql As String = "SELECT Some Stuff"
Dim connection As New SqlConnection(connectionString)
Dim dataadapter As New SqlDataAdapter(sql, connection)
Dim ds As New DataSet()
connection.Open()
dataadapter.Fill(ds, "my_table")
connection.Close()
DataGridView1.DataSource = ds
DataGridView1.DataMember = "my_table"`

End Sub
using SP:

Dim da As New SqlDataAdapter, ds As New DataSet
Dim conn As New SqlConnection

conn.ConnectionString = "Data Source=MyServer;Initial
Catalog=MyDB;UID=MyUID;pwd=MyPWD"
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandType = CommandType.StoredProcedure
da.SelectCommand.CommandText = "dbo.testproc"
da.Fill(ds, "tbl1")
DataGridView1.DataSource = ds.Tables("tbl1")
ExportDatasetToCsv(ds)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top