| | |
Stored Procedure Help Needed.
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 3
Reputation:
Solved Threads: 0
Good afternoon all,
I'm pretty new to VB.Net. Trying to get my head round using stored procedures to manipulate data in a database at the moment. I have managed to use a stored procedure (via my windows form) to insert data into a database but I am struggling to retreive data from my database.
I have a simple stored procedure as follows:
I then have then have the following code in my button_click event handler, the aim is to display the data recrieved in 3 textboxes. I don't get any error messages but I don't get the data either:
Any help would be greatly appreciated.
Regards,
Bern
I'm pretty new to VB.Net. Trying to get my head round using stored procedures to manipulate data in a database at the moment. I have managed to use a stored procedure (via my windows form) to insert data into a database but I am struggling to retreive data from my database.
I have a simple stored procedure as follows:
ALTER PROCEDURE dbo.RBTestSP1 (@Number1 Int OUTPUT, @Number2 Int OUTPUT, @Date DateTime OUTPUT) AS SELECT top 1 Number1, Number2, Date from RBTest order by Date desc
I then have then have the following code in my button_click event handler, the aim is to display the data recrieved in 3 textboxes. I don't get any error messages but I don't get the data either:
Dim myConnection As New SqlConnection(connection string goes here)
Dim myCommand As New SqlCommand("Name of stored procedure", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
Try
myConnection.Open()
Dim number1Param As New SqlParameter("@Number1", SqlDbType.Int, 4)
number1Param.Direction = ParameterDirection.Output
myCommand.Parameters.Add(number1Param)
Dim number2Param As New SqlParameter("@Number2", SqlDbType.Int, 4)
number2Param.Direction = ParameterDirection.Output
myCommand.Parameters.Add(number2Param)
Dim dateParam As New SqlParameter("@Date", SqlDbType.DateTime, 8)
dateParam.Direction = ParameterDirection.Output
myCommand.Parameters.Add(dateParam)
Dim reader As SqlDataReader = myCommand.ExecuteReader()
number1TextBox.Text = CStr(number1Param.Value)
number2TextBox.Text = CStr(number2Param.Value)
dateTextBox.Text = CStr(dateParam.Value)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
myConnection.Close()
End TryAny help would be greatly appreciated.
Regards,
Bern
•
•
Join Date: Jul 2007
Posts: 14
Reputation:
Solved Threads: 0
You'll need to select your results INTO the output parameters. Your current sp will return a dataSET, not individual results.
I think. It's been a while since I've done any SQL Server
SQL Syntax (Toggle Plain Text)
ALTER PROCEDURE dbo.RBTestSP1 (@Number1 INT OUTPUT, @Number2 INT OUTPUT, @DATE DATETIME OUTPUT) AS SELECT top 1 Number1 INTO @number1, Number2 INTO @number2, DATE INTO @DATE FROM RBTest ORDER BY DATE desc
I think. It's been a while since I've done any SQL Server
•
•
Join Date: Feb 2008
Posts: 3
Reputation:
Solved Threads: 0
I have managed to get this to work with the following amendment to my stored procedure:
Regards,
Bern.
ALTER PROCEDURE dbo.RBTestSP1 (@Number1 Int OUTPUT, @Number2 Int OUTPUT, @Date DateTime OUTPUT) AS SELECT top 1 @Number1 = Number1, @Number2 = Number2, @Date = Date from RBTest order by Date desc
Regards,
Bern.
![]() |
Similar Threads
- Return value from Stored Procedure to TextBox (ASP.NET)
- TopN/Sort Group (VB.NET)
- WizardSteps-> SQL Insert -> Grab ID field (ASP.NET)
- Primary key auto_increment to be P2006xxxx (MySQL)
- Help Needed (Oracle)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
- Text data type troubles in T-SQL (Database Design)
Other Threads in the VB.NET Forum
- Previous Thread: textbox string to form name
- Next Thread: software developer for financial systems needed
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial shutdown soap sorting survey table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web webbrowser winforms wpf year





