I have an ASP.NET Wizard for registration.
In step 1, I have few controls that goes into table dbo.Emp. In this step1, I have couple of DropDownList that is binded from code-behind from different table called dbo.Emptype.
However, while inserting the form to table dbo.Emp, I am getting following error-
Insert Error:Error converting data type nvarchar to numeric.
I do not know for which control it is telling it for.
But there is a statement here-
cmd.Parameters.AddWithValue("@EmpType",DropDownList1.SelectedIndex);
cmd.Parameters.AddWithValue("@DeptID", DropDownList3.SelectedIndex);
I want the INT values that is associated with items in EmpType to be inserted into the table.
DropDownList1 is binded to the table called Dbo.EmpType (TypeID (PK- AutoIncrement)| Type)
So, when a user drops down that control and select value, I need DataValueField (i.e TypeID) to get inserted into the table.
What do I do?
This is my bind class.
public void dropdowntype()
{
SqlConnection myConn = new SqlConnection(@"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=KKSTech;Integrated Security=True");
SqlCommand myCmd = new SqlCommand(
"SELECT Type, TypeID FROM EmpType", myConn);
myConn.Open();
SqlDataReader myReader3 = myCmd.ExecuteReader();
//Set up the data binding.
Emp_type.DataSource = myReader3;
Emp_type.DataTextField = "Type";
Emp_type.DataValueField = "TypeID";
Emp_type.DataBind();
//Close the connection.
myConn.Close();
myReader3.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack))
{
dropdownDept();
dropdowntype();
dropdownskills();
}
}
If you need the data value feild from your dropdown then use this statement
You are currently selecting the index of the dropdown.