这是我的代码:try
{
string phone = this.texone.Text.Trim();
string pwd = this.txtpwd.Text.Trim();
string pwd2 = this.textpwd2.Text.Trim();
string name = this.texname.Text.Trim();
string sex = "";
if (this.ckboy.Checked == true)
{
sex = "0";
}
else
{
sex = "1";
}
string Adress = this.txtAdress.Text.Trim();
string Idcard = this.txtIdCard.Text.Trim();
if (pwd.Equals(pwd2))
{
}
else
{
MessageBox.Show("两次密码不相等");
this.txtpwd.Focus();
}
con = new SqlConnection(conString);
con.Open();
string sql = string.Format("INSERT [User] VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", phone, pwd, name, sex, Idcard, Adress);
SqlCommand com = new SqlCommand(sql, con);
int isRet = com.ExecuteNonQuery();
if (isRet>= 1)
{
MessageBox.Show("注册成功!");
}
else
{
MessageBox.Show("注册失败!");
}
}
catch (Exception)
{
MessageBox.Show("出现异常!");
throw;
}
con.Close();
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("确定要退出吗?");
this.Close();
}
是不是输入了中文?代码没什么异常
貌似是顺序问题,你的sql语句中的顺序不匹配
idcard是多少位 表就两字节 一个字就够了
phone, pwd, name, sex, Idcard, Adress;这几个其中一个文本太长,只能是这个原因了
楼主 麻烦您把User表截图给我看下 , 在这里我提个思路:
string sql = string.Format("INSERT [User] VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", phone, pwd, name, sex, Idcard, Adress);
改成:
string sql = string.Format("INSERT [User] VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", phone, pwd, name, Idcard,sex,Adress);
还不行的话 麻烦您把那个表截图给我看下 不要只截数据类型。