Return value
-
i have SAVE function and a stored procedure ("JobsDb_ContactInfo_InsertUpdateSingleItem" which return "returnValue" which is returned value integer of inserted UserId please help me get returned value UserID i am trying to get Profile.UserId =Returned value of stored procedure UserId This is the code i have in web form to save data
If Not (Profile.UserId = -1) Then myContactInfo.UserID = Profile.UserId [ContactInfoManager].Save(myContactInfo) Else Dim result As Integer = ContactInfoManager.Save(myContactInfo) Profile.UserId = result ) End If
this is the Save functionPublic Shared Function Save(ByVal myContactInfo As ContactInfo) As Integer Dim result As Integer = 0 ' Using Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString) Try Dim myCommand As SqlCommand = New SqlCommand("JobsDb_ContactInfo_InsertUpdateSingleItem", myConnection) myCommand.CommandType = CommandType.StoredProcedure myCommand.Parameters.AddWithValue("@Userid", UserId) Dim returnValue As DbParameter returnValue = myCommand.CreateParameter returnValue.Direction = ParameterDirection.ReturnValue myCommand.Parameters.Add(returnValue) myConnection.Open() myCommand.ExecuteNonQuery() result = Convert.ToInt32(returnValue.Value) myConnection.Close() Finally CType(myConnection, IDisposable).Dispose() End Try Return result End Function
appu
-
i have SAVE function and a stored procedure ("JobsDb_ContactInfo_InsertUpdateSingleItem" which return "returnValue" which is returned value integer of inserted UserId please help me get returned value UserID i am trying to get Profile.UserId =Returned value of stored procedure UserId This is the code i have in web form to save data
If Not (Profile.UserId = -1) Then myContactInfo.UserID = Profile.UserId [ContactInfoManager].Save(myContactInfo) Else Dim result As Integer = ContactInfoManager.Save(myContactInfo) Profile.UserId = result ) End If
this is the Save functionPublic Shared Function Save(ByVal myContactInfo As ContactInfo) As Integer Dim result As Integer = 0 ' Using Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString) Try Dim myCommand As SqlCommand = New SqlCommand("JobsDb_ContactInfo_InsertUpdateSingleItem", myConnection) myCommand.CommandType = CommandType.StoredProcedure myCommand.Parameters.AddWithValue("@Userid", UserId) Dim returnValue As DbParameter returnValue = myCommand.CreateParameter returnValue.Direction = ParameterDirection.ReturnValue myCommand.Parameters.Add(returnValue) myConnection.Open() myCommand.ExecuteNonQuery() result = Convert.ToInt32(returnValue.Value) myConnection.Close() Finally CType(myConnection, IDisposable).Dispose() End Try Return result End Function
appu
what is the error? how is it failing?
MrPlankton
-
i have SAVE function and a stored procedure ("JobsDb_ContactInfo_InsertUpdateSingleItem" which return "returnValue" which is returned value integer of inserted UserId please help me get returned value UserID i am trying to get Profile.UserId =Returned value of stored procedure UserId This is the code i have in web form to save data
If Not (Profile.UserId = -1) Then myContactInfo.UserID = Profile.UserId [ContactInfoManager].Save(myContactInfo) Else Dim result As Integer = ContactInfoManager.Save(myContactInfo) Profile.UserId = result ) End If
this is the Save functionPublic Shared Function Save(ByVal myContactInfo As ContactInfo) As Integer Dim result As Integer = 0 ' Using Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString) Try Dim myCommand As SqlCommand = New SqlCommand("JobsDb_ContactInfo_InsertUpdateSingleItem", myConnection) myCommand.CommandType = CommandType.StoredProcedure myCommand.Parameters.AddWithValue("@Userid", UserId) Dim returnValue As DbParameter returnValue = myCommand.CreateParameter returnValue.Direction = ParameterDirection.ReturnValue myCommand.Parameters.Add(returnValue) myConnection.Open() myCommand.ExecuteNonQuery() result = Convert.ToInt32(returnValue.Value) myConnection.Close() Finally CType(myConnection, IDisposable).Dispose() End Try Return result End Function
appu
-
i have SAVE function and a stored procedure ("JobsDb_ContactInfo_InsertUpdateSingleItem" which return "returnValue" which is returned value integer of inserted UserId please help me get returned value UserID i am trying to get Profile.UserId =Returned value of stored procedure UserId This is the code i have in web form to save data
If Not (Profile.UserId = -1) Then myContactInfo.UserID = Profile.UserId [ContactInfoManager].Save(myContactInfo) Else Dim result As Integer = ContactInfoManager.Save(myContactInfo) Profile.UserId = result ) End If
this is the Save functionPublic Shared Function Save(ByVal myContactInfo As ContactInfo) As Integer Dim result As Integer = 0 ' Using Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString) Try Dim myCommand As SqlCommand = New SqlCommand("JobsDb_ContactInfo_InsertUpdateSingleItem", myConnection) myCommand.CommandType = CommandType.StoredProcedure myCommand.Parameters.AddWithValue("@Userid", UserId) Dim returnValue As DbParameter returnValue = myCommand.CreateParameter returnValue.Direction = ParameterDirection.ReturnValue myCommand.Parameters.Add(returnValue) myConnection.Open() myCommand.ExecuteNonQuery() result = Convert.ToInt32(returnValue.Value) myConnection.Close() Finally CType(myConnection, IDisposable).Dispose() End Try Return result End Function
appu
-
what is the error? how is it failing?
MrPlankton
it is giving no error but the data is not getting saved and the Profile.UserId is changing from -1 which is default to 0 please help me getting this solved as i m new to asp.net and the main Relational Key of all my database table is UserId and untill this is not solved i cant go any further...i have excecuted my stored procedure manualy and it is returning value of UserId but some how i made mistake in code os save function..
appu
-
it is giving no error but the data is not getting saved and the Profile.UserId is changing from -1 which is default to 0 please help me getting this solved as i m new to asp.net and the main Relational Key of all my database table is UserId and untill this is not solved i cant go any further...i have excecuted my stored procedure manualy and it is returning value of UserId but some how i made mistake in code os save function..
appu
It's been a while since I did any vb stuff but I suspect the problem is that you the return value needs to be an int and I believe you the add has a type argument as well that you need to specify. Dim returnValue As DbParameter (make int) returnValue = myCommand.CreateParameter returnValue.Direction = ParameterDirection.ReturnValue myCommand.Parameters.Add(returnValue) (add type to add, type would be SqlDbType.Int) here is an example in c# and this works. MyError = "adding ReturnValue parameter"; SqlC.Parameters.Add("@RETURN_VALUE", SqlDbType.Int); SqlC.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue; MyError = "building exec string for stored procedure"; string cmd = "DeleteDateRange"; SqlC.CommandType = CommandType.StoredProcedure; SqlC.CommandText = cmd; MyError = "Executing query, calling DeleteDateRange"; ReturnValue = SqlC.ExecuteNonQuery(); ReturnValue = Convert.ToInt32(SqlC.Parameters["@RETURN_VALUE"].Value); 2 cents, good luck.
MrPlankton