Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I want insert some data in my Education_Degree_TB but I face to bellow error
why it happen what I do?
Please help me

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: Procedure or function 'Insert_Education_Degree_TB' expects parameter '@Person_ID', which was not supplied.


my Procedure code

CREATE procedure [dbo].[Insert_Education_Degree_TB]
@Person_ID int,
@Field_ID int,
@SubField_ID int,
@Degree_Education nvarchar(50),
@University_Name nvarchar(100),
@Data_Graduated date,
@Experience_Job nvarchar(50)

as
begin
Insert into Education_Degree_TB values(@Person_ID,@Field_ID,@SubField_ID,@Degree_Education,@University_Name,
@Data_Graduated,@Experience_Job )
end


My C# code

protected void ButtonEducationDgree_Click(object sender, EventArgs e)
{
    SqlCommand cmd2 = new SqlCommand("Insert_Education_Degree_TB", con);
    cmd2.CommandType = CommandType.StoredProcedure;
    cmd2.Parameters.AddWithValue("@Person_ID",Session["PersonID"].ToString());
    cmd2.Parameters.AddWithValue("@Field_ID", DropDownList_PersonField.SelectedValue.ToString());
    cmd2.Parameters.AddWithValue("@SubField_ID", DropDownList_PersonSubField.SelectedValue.ToString());
    cmd2.Parameters.AddWithValue("@Degree_Education", DropDownList_PersonDegree.SelectedValue.Trim());
    cmd2.Parameters.AddWithValue("@University_Name", TextBox_UniversityNmae.Text.Trim());
    cmd2.Parameters.AddWithValue("@Data_Graduated", TextBox_DateGraduated.Text.Trim());
    cmd2.Parameters.AddWithValue("@Experience_Job", DropDownList_Experience.SelectedValue);
    cmd2.Parameters.Clear();
    con.Open();
    cmd2.ExecuteNonQuery();
    Labelsucces.Visible = true;
    Labelsucces.Text = "Insert Education was Sucsessfuly";
    TextBox_UniversityNmae.Text = "";
    TextBox_DateGraduated.Text = "";
    LblErorr.Visible = false;
    con.Close();


}//--------end of Btton Education
Posted
Comments
CHill60 26-Feb-15 10:07am    
Session["PersonID"] is empty
ZurdoDev 26-Feb-15 10:12am    
Empty string is OK. Null would give the SQL error OP has but then calling .ToString() would have given an object reference error first.

If you look closely, OP clears parameters after filling them all in and before calling ExecuteNonQuery. :)
phil.o 26-Feb-15 10:17am    
Also, since the Person_ID parameter is defined as an int, you have to provide it an int, not a string value.
[no name] 26-Feb-15 10:45am    
Use particular columns in the insert statement to which you are inserting the values.

like

Insert into Education_Degree_TB (field1, field2,...,field7) values(@Person_ID,@Field_ID,@SubField_ID,@Degree_Education,@University_Name,
@Data_Graduated,@Experience_Job

1 solution

Right after you add all the parameters you then clear them out.

Remove this line:
cmd2.Parameters.Clear();
 
Share this answer
 
Comments
phil.o 26-Feb-15 10:16am    
5'd :)
CHill60 26-Feb-15 10:27am    
Good spot!
Member 11240896 26-Feb-15 13:05pm    
I remove this Line cmd2.Parameters.Clear();
but now I face to below error
Additional information: Error converting data type nvarchar to date.
ZurdoDev 26-Feb-15 13:14pm    
Do you understand what the error means? It says that you are passing a string into a date parameter that is not an actual date.
Member 11240896 26-Feb-15 13:25pm    
Actually I did not understand what the error means. When I insert the data, I receive the input from session also the Data Type of my Parameter is int

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900