I am trying to insert data using a SP as follows:
ALTER PROCEDURE [dbo].[AddTrainingRoomRq]
@req_start_date DateTime,
@req_end_date DateTime,
@req_times text,
@requestor_name text,
@requestor_phone text,
@requestor_mail_symbol text,
@requestor_email text,
@class_name text,
@user_num text,
@other_software text,
@internet_access bit,
@intranet_access bit,
@other_logons bit,
@other_logon_list text,
@additional_comments varchar (500),
@Result nvarchar (500) output
AS
BEGIN
Declare
@ClassID int
Set @ClassID = (SELECT CAST(RAND() * 1000000000 AS INT) AS [RandomNumber])
INSERT INTO cal_tr_requests
(ClassID, req_start_date, req_end_date, req_times, requestor_name, requestor_phone, requestor_mail_symbol, requestor_email, class_name, user_num, other_software,
internet_access, intranet_access, other_logons, other_logon_list, additional_comments, date_of_req)
VALUES (@ClassID,@req_start_date,@req_end_date,@req_times,@requestor_name,@requestor_phone,@requestor_mail_symbol,@requestor_email,@class_name,@user_num,@other_software,
@internet_access,@intranet_access,@other_logons,@other_logon_list,@additional_comments,getdate())
Set @Result = Convert(nvarchar,@ClassID)
END
My code behind:
<pre lang="c#"{
public partial class trainingroom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String strSysDt = Convert.ToString(System.DateTime.Now);
}
protected void lbInsert_Click(object sender, EventArgs e)
{
string strReqNm = ((TextBox)fvAddBookingInfo.FindControl("txtReqName")).Text;
string strPhone = ((TextBox)fvAddBookingInfo.FindControl("txtPhone")).Text;
string strMailSymbol = ((TextBox)fvAddBookingInfo.FindControl("txtMailSym")).Text;
string strEmail = ((TextBox)fvAddBookingInfo.FindControl("txtEmail")).Text;
string strFirstDt = ((TextBox)fvAddBookingInfo.FindControl("txtFirstDt")).Text;
string strLastDt = ((TextBox)fvAddBookingInfo.FindControl("txtLastDt")).Text;
string strUseTime = ((TextBox)fvAddBookingInfo.FindControl("txtUseTime")).Text;
string strClassTy = ((TextBox)fvAddBookingInfo.FindControl("txtClass")).Text;
string strNumOfUsr = ((TextBox)fvAddBookingInfo.FindControl("txtNumOfUsr")).Text;
string strOtherSW = ((TextBox)fvAddBookingInfo.FindControl("txtOtherSW")).Text;
CheckBox ckInternet = (CheckBox)fvAddBookingInfo.FindControl("cbInternet");
CheckBox ckIntranet = (CheckBox)fvAddBookingInfo.FindControl("cbIntranet");
CheckBox ckOthrLog = (CheckBox)fvAddBookingInfo.FindControl("cbOtherLog");
string strListOthLog = ((TextBox)fvAddBookingInfo.FindControl("txtOtherLogList")).Text;
string strComment = ((TextBox)fvAddBookingInfo.FindControl("txtComment")).Text;
String strSysDt = Convert.ToString(System.DateTime.Now);
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["CFMAppsConnectionString"].ConnectionString;
cmd.Connection = conn;
cmd.CommandText = "AddTrainingRoomRq";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@requestor_name", SqlDbType.NVarChar).Value = strReqNm;
cmd.Parameters.Add("@requestor_phone", SqlDbType.NVarChar).Value = strPhone;
cmd.Parameters.Add("@requestor_mail_symbol", SqlDbType.NVarChar).Value = strMailSymbol;
cmd.Parameters.Add("@requestor_email", SqlDbType.NVarChar).Value = strEmail;
cmd.Parameters.Add("@req_start_date", SqlDbType.DateTime).Value = strFirstDt;
cmd.Parameters.Add("@req_end_date", SqlDbType.DateTime).Value = strLastDt;
cmd.Parameters.Add("@req_times", SqlDbType.NVarChar).Value = strUseTime;
cmd.Parameters.Add("@class_name", SqlDbType.NVarChar).Value = strClassTy;
cmd.Parameters.Add("@user_num", SqlDbType.NVarChar).Value = strNumOfUsr;
cmd.Parameters.Add("@other_software", SqlDbType.NVarChar).Value = strOtherSW;
cmd.Parameters.Add("@other_logon_list", SqlDbType.NVarChar).Value = strListOthLog;
cmd.Parameters.Add("@additional_comments", SqlDbType.NVarChar).Value = strComment;
cmd.Parameters.Add("@date_of_req", SqlDbType.DateTime).Value = strSysDt;
if (ckInternet.Checked)
{
cmd.Parameters.Add("@internet_access", SqlDbType.Bit).Value = 1;
}
else
{
cmd.Parameters.Add("@internet_access", SqlDbType.Bit).Value = 0;
}
if (ckIntranet.Checked)
{
cmd.Parameters.Add("@intranet_access", SqlDbType.Bit).Value = 1;
}
else
{
cmd.Parameters.Add("@intranet_access", SqlDbType.Bit).Value = 0;
}
if (ckOthrLog.Checked)
{
cmd.Parameters.Add("@other_logons", SqlDbType.Bit).Value = 1;
}
else
{
cmd.Parameters.Add("@other_logons", SqlDbType.Bit).Value = 0;
}
SqlParameter outPutParameter = new SqlParameter();
outPutParameter.ParameterName = "@Result";
outPutParameter.SqlDbType = System.Data.SqlDbType.NVarChar;
outPutParameter.Size = 500;
outPutParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
string Result = outPutParameter.Value.ToString();
lblResultMsg.Text = Result;
}
}
}>
I am getting error:
Procedure or function has too many arguments specified.
Please help!
What I have tried:
I searched and tried a few solution without success.