Hello everyone. I'm working on an application and I keep getting this exception when i run the code listed below. I'm new here. Please help.
My connection string in My Global.asax file:
Application["connstr"] = "data source=SERVER\\VSDOTNET;initial catalog=MedicalCenterDB;integrated security=SSPI;persis" +
"t security info=False;workstation id=SERVER";
private void submitbtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
System.Data.SqlClient.SqlConnection cn;
System.Data.SqlClient.SqlConnection cn2;
System.Data.SqlClient.SqlCommand cmd;
System.Data.SqlClient.SqlCommand cmd2;
System.Data.SqlClient.SqlDataReader dr;
cn = new System.Data.SqlClient.SqlConnection();
cn2 = new System.Data.SqlClient.SqlConnection();
cn.ConnectionString = Application["connstr"].ToString();
cn2.ConnectionString = Application["connstr"].ToString();
cmd = new System.Data.SqlClient.SqlCommand("selectUserfromCard",cn);
cmd2 = new System.Data.SqlClient.SqlCommand("saveUser",cn2);
cmd.CommandType=CommandType.StoredProcedure;
cmd2.CommandType=CommandType.StoredProcedure;
try
{
cn.Open();
cmd.Parameters.Add("@idcard",idcard.Text);
//
//cmd2
//
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if(dr.Read())
{
resultlbl.Text = "A User with this Card already exists";
}
else
{
string dob = this.bday.SelectedItem.Value.ToString() + "/" + this.bmonth.SelectedItem.Value.ToString() + "/" + this.byear.SelectedItem.Value.ToString();
cmd2.Parameters.Add("@idcard",idcard.Text);
cmd2.Parameters.Add("@Password",password.Value);
cmd2.Parameters.Add("@Firstname",Firstname.Text);
cmd2.Parameters.Add("@Lastname",Lastname.Text);
cmd2.Parameters.Add("@Othername",Othername.Text);
cmd2.Parameters.Add("@Sex",this.sex.SelectedItem.Value.ToString());
cmd2.Parameters.Add("@Email",email.Text);
cmd2.Parameters.Add("@Nationality",Nationality.Text);
cmd2.Parameters.Add("@State",State.Text);
cmd2.Parameters.Add("@Tribe",Tribe.Text);
cmd2.Parameters.Add("@Occupation",Occupation.Text);
cmd2.Parameters.Add("@dateofbirth",dob);
cn2.Open();
cmd2.ExecuteNonQuery();
resultlbl.Text = "Info Saved";
}
}
catch(System.Exception eLoad)
{
resultlbl.Text = eLoad.Message;
}
finally
{
cn.Close();
cn2.Close();
}
}
Thanks a lot.
vijay kumarPosted Feb 6, 2008, 5:28 AM
Mike HildnerPosted Oct 25, 2006, 9:12 PM
This is usually pretty easy to track down. What it means is that your code is defining more arguments than the stored procedure is defined to accept.
You've got a couple connections and stored procedures in your code, which is confusing, at least to me. That may be another issue, but for now, can you please let us know which line of code is generating the error? That would be very helpful.
Regardless, to track it down, you need to compare the parameters that you're sending versus the parameters that your stored procedure accepts. Make sure that the 'selectUserfromCard' stored procedure accepts @idcard, and that the 'saveUser' sproc accepts all the parameters you are trying to send it.
I hope that makes sense. If not, please post the two stored procedures.
Regards,
Mike