Hello,
My code is:
protected void Button1_Click(object sender, EventArgs e)
{
string EducatorName = tbEducatorName.ToString();
string Educatorfamilyname = tbEducatorFamilyname.ToString();
int Hisclass =Int32.Parse(ddlClasses.DataValueField.ToString());
SqlConnection conn = new SqlConnection(DBconn);
SqlCommand cmd = new SqlCommand("AddNewEducator", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "AddNewEducator";
cmd.Parameters.Add("@EducatorName", SqlDbType.VarChar).Value = EducatorName;
cmd.Parameters.Add("@Educatorfamilyname", SqlDbType.VarChar).Value = Educatorfamilyname;
cmd.Parameters.Add("@EducatorClass", SqlDbType.Int).Value = Hisclass;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
dbErrorLabel.Text = ex.Message.ToString();
}
finally
{
conn.Close();
}
}
Stored Procedure:
create procedure [dbo].[AddNewEducator]
@EducatorName nvarchar(20),
@EducatorFamilyname nvarchar(20),
@EducatorClass int
as
insert into Educators
(
EducatorName,
EducatorFamilyname,
EducatorClass
)
values
(
@EducatorName,
@EducatorFamilyname,
@EducatorClass
)
well, when i try to execute this method it says
int Hisclass =Int32.Parse(ddlClasses.DataValueField.ToString());
Format exception.
cmd.Parameters.Add("@EducatorClass", SqlDbType.Int).Value = Hisclass;
and this is a value I want to get from dropdownlist and insert it into DB
Please help