By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,312 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,312 IT Pros & Developers. It's quick & easy.

datagridview not populating from stored procedure

P: n/a

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
Share this Question
Share on Google+
1 Reply

P: n/a

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 ***
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.