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

code for insert values into database using stored procedures

P: n/a
Hi,

I am inserting values into databse using sqlserver stored
procedures. i wrote stored preocedure,but in codebehind file(.vb
file)
i dont know how to pass the parameters, i got error message like this
"System.Data.SqlClient.SqlException: Procedure or Function
'sp_insert'
expects parameter '@TestId', which was not supplied. at
System.Data.SqlClient.SqlConnection"
I wrote Stored Procedure Like this:
ALTER PROCEDURE [dbo].[sp_insert]
(@TestId int output ,
@Name varchar(50),
@Number varchar(50),
@Date Datetime
)
AS
INSERT INTO Testtable(Name, Number,Date)
VALUES
(@Name, @Number,@Date)
SELECT @TestId=@@IDENTITY.
This is My .vb code:
sqlcon = New
SqlConnection(System.Configuration.ConfigurationMa nager.AppSettings("Connec*
tionstring"))
Try
sqlcon.Open()
sqlcmd = New SqlCommand("sp_insert", sqlcon)
sqlcmd.CommandText = "sp_insert"
sqlcmd.Connection = sqlcon
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.Parameters.Add("@Name", SqlDbType.VarChar).Value =
txtname.Text
sqlcmd.Parameters.Add("@Number", SqlDbType.VarChar).Value
= txtnumber.Text
sqlcmd.Parameters.Add("@Date", SqlDbType.DateTime).Value
=
txtdate.Text
param = sqlcmd.Parameters.Add("@RetunValue",
SqlDbType.VarChar, 50)
param.Direction = ParameterDirection.Output
sqlcmd.ExecuteNonQuery()
lblstatus.Text = "successfullyinserted"
sqlcon.Close()
ReturnValue = param.Value
Catch ex As Exception
lblstatus.Text = ex.ToString
End Try.
Please check this code and find out my Error.

i dont know how to pass that output parameter, please write that
code .

Regards,
Sirisha.
Regards,
Sirisha.

Feb 22 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.