添加数据添加不进去,大家帮我看看吧!
程序代码:
Help help = new Help(); private void btnBaocun_Click(object sender, EventArgs e) { try { Help.conn.Open();//打开数据库 string sex; //设置性别变量 if (rbMan.Checked) {[local]1[/local] sex = "男"; } else { sex = "女"; } //数据库语句 string sql = string.Format("insert into Reader(Number,ReaderName,Sex,ReaderTypeID,PapersID,No,Phone,RegisterDate,UserID)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", this.txtTiaoxingma.Text, this.txtXingming.Text, sex,this.cboLeixing.Text,this.cboUserPapers.Text, this.txtZHM.Text, this.txtLianxi.Text, this.dtpRegister.Text,this.txtCaozuoyuan.Text); SqlCommand comm = new SqlCommand(sql, Help.conn);//创建command对象 if (comm.ExecuteNonQuery() > 0) { MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { MessageBox.Show("出现异常!"); } finally { Help.conn.Close();//关闭数据库 } }那个类型和证件号码都已经绑定了数据,错的是数据库语句那里,但是不知道怎么改?
[ 本帖最后由 佳L 于 2012-3-13 21:47 编辑 ]