C# 必须声明标量变量"@Emp_ID";
@员工ID应为@Emp\u ID,与您的查询相同 例如:C# 必须声明标量变量"@Emp_ID";,c#,asp.net,C#,Asp.net,@员工ID应为@Emp\u ID,与您的查询相同 例如: cmd.Parameters.AddWithValue(“@Emp\u ID”,txtEmp\u ID.Text) 因此,请尝试以下方法: 或者,您可以将值更改为: con.Open(); SqlCommand cmd= new SqlCommand("Insert into Tbl_EmployeeDetails(Name,Address,Contact,Emp_ID,JobLocation,DateOfBirth,Ge
cmd.Parameters.AddWithValue(“@Emp\u ID”,txtEmp\u ID.Text)代码>
因此,请尝试以下方法:
或者,您可以将值更改为:
con.Open();
SqlCommand cmd= new SqlCommand("Insert into Tbl_EmployeeDetails(Name,Address,Contact,Emp_ID,JobLocation,DateOfBirth,Gender)values(@Name,@Address,@Contact,@Emp_ID,@JobLocation,@DateOfBirth,@Gender)",con);
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@Contact", txtContact.Text);
cmd.Parameters.AddWithValue("@Emp_ID", txtEmp_ID.Text);
cmd.Parameters.AddWithValue("@JobLocation", txtJobLocation.Text);
cmd.Parameters.AddWithValue("@DateOfBirth", txtDateOfBirth.Text);
cmd.Parameters.AddWithValue("@Gender", Rdllist.SelectedItem.Text);
cmd.ExecuteNonQuery();
ScriptManager.RegisterClientScriptBlock(this,this.GetType(),"alertMessage","alert('Record Inserted Successfully')",true);
txtName.Text= String.Empty;
txtAddress.Text= String.Empty;
txtContact.Text= String.Empty;
txtEmp_ID.Text= String.Empty;
txtJobLocation.Text= String.Empty;
txtDateOfBirth.Text= String.Empty;
// txtGender.Text= String.Empty;
con.Close();
}
}
既然你这样称呼它:
values(@Name,@Address,@Contact,@Employee_ID,@JobLocation,@DateOfBirth,@Gender)
或
值中的名称将在cmd.parameters.addwithvalue中使用
当心AddWithValue的陷阱:在提问之前,请阅读“如何提问好问题”:欢迎来到Stack Overflow。到目前为止你试过什么?
values(@Name,@Address,@Contact,@Employee_ID,@JobLocation,@DateOfBirth,@Gender)
cmd.Parameters.AddWithValue("@Employee_ID", txtEmp_ID.Text);
values(@Name,@Address,@Contact,@Emp_ID,@JobLocation,@DateOfBirth,@Gender)
cmd.Parameters.AddWithValue("@Emp_ID", txtEmp_ID.Text);