472,951 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

return value from sql server insert proc


I am a newbie with vb.net. I am working with vb.net 2.0 and sql server 2005.
I am trying to get the return value from my insert stored proc.Does anyone
know how to do this?



Jan 13 '07 #1
1 4464

"Eric Effer" <be****@gmail.comwrote in message

I am a newbie with vb.net. I am working with vb.net 2.0 and sql server
I am trying to get the return value from my insert stored proc.Does anyone
know how to do this?


Just include an integer to receive the results of the call to the stored
proc. In C# it's like this:
int rowsInserted = cmdUpdateReminders.ExecuteNonQuery();

vb must be near identical syntax
the full C# listing:

public string InsertRemindersRecord(string p_eMailAddress, DateTime
p_requestedSendDateTime, string p_timeZone, string p_messageHeader, string
SqlConnection cq = new SqlConnection("xxx");
SqlCommand cmdUpdateReminders = new
SqlCommand("spInsertRemindersRecord", cq);
cmdUpdateReminders.CommandType = CommandType.StoredProcedure;

SqlDbType.NVarChar, 99);
cmdUpdateReminders.Parameters["@eMailAddress"].Value =

cmdUpdateReminders.Parameters.Add("@requestedSendD ateTime",
cmdUpdateReminders.Parameters["@requestedSendDateTime"].Value =

cmdUpdateReminders.Parameters.Add("@timeZone", SqlDbType.NVarChar,
cmdUpdateReminders.Parameters["@timeZone"].Value = p_timeZone;

cmdUpdateReminders.Parameters.Add("@messageHeader" ,
cmdUpdateReminders.Parameters["@messageHeader"].Value =

cmdUpdateReminders.Parameters.Add("@messageBody", SqlDbType.NText);
cmdUpdateReminders.Parameters["@messageBody"].Value = p_messageBody;

// execute the stored proc:
int rowsInserted = cmdUpdateReminders.ExecuteNonQuery();
_msgBack = rowsInserted + " record inserted";
return _msgBack;
catch (Exception ex)
string _full_msgBack = ex.Message;
if (_full_msgBack.Substring(0, 24) == "Violation of PRIMARY
_msgBack = "This record already exists";
_msgBack = _full_msgBack;

return _msgBack;
Jan 14 '07 #2

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

Similar topics

by: ree32 | last post by:
I am inserting a record into a table that automatically generates unique ids (i.e. Primary Key). Is there anyway to return this id. As I am using this on ASP.net page and I really need the ID to...
by: Gunnar Liknes | last post by:
Hi, Is it possible to make a stored procedure or function to generate a return value? I have a stored procedure which inserts a new row in a table. I would like that proceudre to return the...
by: CSDunn | last post by:
Hello, In Access ADP's that connect to SQL Server databases, any time I have a situation where I have a combo box in a main form that looks up a record in a subform, the subform record source has...
by: ASP .NET Newbie | last post by:
I am trying to insert a new record into my database, and have it return a uniqueidentifier as the "newcatid". I don't use integers as my "id"'s, but rather uniqueidentifiers. Here's my Stored...
by: Phil Mc | last post by:
Trying to call a stored proc but some times don't want to have values inserted in some fields. Hi I am rewriting a VBS script which called a stored proc in a SQL server db. The proc takes a...
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
by: raghav | last post by:
Hi all I am having a SP which is returning a value......Now I have to store that value in session...I saw some examples in msdn lib ----> string Name=string.Empty; Session=Name.ToString(); ...
by: jbonifacejr | last post by:
Hi. I'm sorry to bother all of you, but I have spent two days looking at code samples all over the internet, and I can not get a single one of them to work for me. I am simply trying to get a value...
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.