469,602 Members | 2,012 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

datagridview not populating from stored procedure


I am using VB 2008 with SQL Server 2000 and SQL Server 2005 (depending
which server the user selects to connect to).

I have a listbox in which the user select the server to connect to.

Another listbox that shows the databases in that particular server.

Another listbox with the filesets from the selected database above.

When the user clicks on button 3, I want the datagridview to populate
data from a stored procedure passing 2 parameters in sql server.

At the moment the datagridview does not populate anything, neither
does it throw an error message. I have no clue what is wrong and I am
new to VB.

Your help will be greatly appreciated.


Code for button 3:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

Dim cn As New SqlConnection("Data Source=" &
lstServers.SelectedValue & ";Initial Catalog=" &
lstDatabases.SelectedValue & ";Integrated Security=SSPI")

Dim cmd As New SqlCommand("usp_DR_Spam_BB_Search_get_recs",

Dim dt As New DataTable()

cmd.CommandTimeout = 0
cmd.CommandType = CommandType.StoredProcedure


Dim reader As SqlDataReader = cmd.ExecuteReader()
DataGridView1.DataSource = reader
End Sub
Jun 27 '08 #1
1 3271

Try something like this:

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

conn.ConnectionString = "Data Source=yourServer;Initial
Catalog=yourDB;Integrated Security=True"

da.SelectCommand = New SqlCommand
da.SelectComnmand.Connection = conn
da.SelectCommand.CommandType = CommandType.StoredProcedure
da.SelectCommand.CommandText = "store procedure name"
da.Fill(ds, "tbl1")
Datagridview1.DataSource = ds.Tables("tbl1")


*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Paul | last post: by
10 posts views Thread by michael sorens | last post: by
1 post views Thread by Lewis | last post: by
reply views Thread by jmanuel | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.