473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

datagridview not populating from stored procedure

TG
Hi!

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.

Thanks!

Tammy
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",
cn)

Dim dt As New DataTable()

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

cmd.Parameters.AddWithValue("@Matter",
lstDatabases.SelectedItem)
cmd.Parameters.AddWithValue("@FileSet",
lstFileSets.SelectedItem)

cn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
DataGridView1.DataSource = reader
End Sub
Jun 27 '08 #1
1 3486
Greetings,

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")

Rich

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Paul | last post by:
I sometimes get a timeout error when populating my datagrid, the code is WizardConnection.Open() UpdateCommand.CommandText = "EXECUTE sp_assign_user '" & PhysOffice.SelectedValue & "', '" &...
1
by: jbehrne | last post by:
Hi all, I am using a datagridview in .Net 2005 to display data from a stored procedure using a System.Data.SQLClient connection. After the stored procedure dumps the data into a dataset and the...
0
by: Crazy Cat | last post by:
In the following code I retrieve data from a stored procedure that returns multiple resultsets (the results of the stored procedure have been stored in a datareader called reader). On each...
10
by: michael sorens | last post by:
Is it possible to store an unbound DataGridView component into a setting? I naively tried defining a Setting that is a DataGridView called DGV, then simply assigning it:...
1
by: Lewis | last post by:
Hi, I'm trying to use a DataGridView to display the contents of a SQL view. At this point its easy. Where it gets complicated is that the view is created on the fly by a stored procedure so the...
0
by: jmanuel | last post by:
Hi, I'm using datagridview in vb2005. I'm populating datagridview at run time using SqlDataAdapter and a dataset. This is my situation. User may update some of the records in the datagridview....
1
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
3
by: WestAussie | last post by:
Hello I'm trying to populate a DataGridView with a stored procedure using VB.NET. The query I need to use is within a Access 2007 datadase. When I run it in Access it is showing data but the...
1
by: =?Utf-8?B?VGFtbXk=?= | last post by:
Hi! 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 combox in which the user types the server to connect to. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.