我创建了一个类名EmployeeDAta在这里写这段代码,我想在SQL数据库中插入Radiobutton值
public static void AddEmployee(Employee employee)
{
string connString = ConfigurationManager.ConnectionStrings["Employee"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
using (conn)
{
SqlCommand cmd = new SqlCommand("ADDEMPLOYEE", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = employee.Name;
cmd.Parameters.Add("@FName", SqlDbType.NVarChar, 50).Value = employee.Fname;
cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 50).Value = employee.Address;
cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = employee.Email;
cmd.Parameters.Add("@Mobile", SqlDbType.NVarChar, 50).Value = employee.Mobile;
cmd.Parameters.Add("@Pincode", SqlDbType.NVarChar, 50).Value = employee.Pincode;
cmd.Parameters.AddWithValue("@VB", SqlDbType.Bit).Value = employee.VB;
cmd.Parameters.AddWithValue("@ASP", SqlDbType.Bit).Value = employee.ASP;
cmd.Parameters.AddWithValue("@Gender", SqlDbType.Int).Value = employee.Gender;
conn.Open();
cmd.ExecuteNonQuery();
}
}
答案 0 :(得分:0)
在存储过程调用中添加一个参数:
cmd.Parameters.AddWithValue("@ValueOfRadioButtonr", SqlDbType.Int).Value = MyRadioButton.Value;
在数据库的存储过程中,请确保处理额外参数。