private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection myConn=new SqlConnection("user id=sa;data source=GZY-7E6267900F3;initial catalog=hisbook;password=");
string SqlString="Insert into book values(@name,@pwd,@sex,@phone,@address,@Email)";
SqlCommand myComm=new SqlCommand(SqlString,myConn);
SqlParameter namePara=new SqlParameter("@name",SqlDbType.Char,20);
SqlParameter pwdPara=new SqlParameter("@pwd",SqlDbType.Char,10);
SqlParameter sexPara=new SqlParameter("@sex",SqlDbType.Char,1);
SqlParameter phonePara=new SqlParameter("@phone",SqlDbType.Char,15);
SqlParameter addressPara=new SqlParameter("@address",SqlDbType.Char,30);
SqlParameter EmailPara=new SqlParameter("@Email",SqlDbType.Char,20);
myComm.Parameters.Add(namePara);
myComm.Parameters.Add(pwdPara);
myComm.Parameters.Add(sexPara);
myComm.Parameters.Add(phonePara);
myComm.Parameters.Add(addressPara);
myComm.Parameters.Add(EmailPara);
namePara.Value=TextBox1.Text;
pwdPara.Value=TextBox2.Text;
sexPara.Value=DropDownList2.SelectedItem.Text;
phonePara.Value=TextBox3.Text;
addressPara.Value=TextBox4.Text;
EmailPara.Value=TextBox5.Text;
myConn.Open();
try
{
myComm.ExecuteNonQuery();
// myComm1.ExecuteNonQuery();
Label17.Text="成功";
Label17.Visible=true;
}
catch(Exception excp){
System.Diagnostics.Debug.WriteLine(excp.Message);
Label17.Text="失败";
Label17.Visible=true;
}
}
请问:为什么我加了sex就说插入失败,而去掉sex就可以呢??
请问: “sexPara.Value=DropDownList2.SelectedItem.Text;”我这句语法有错吗??还是其它什么问题??