本帖最后由 赵威 于 2013-4-29 08:59 编辑
我想要做一个注册,但是代码一运行就告诉有错误,求高手解答?
namespace accessshiyan
{
public partial class zhuce : Form
{
public zhuce()
{
InitializeComponent();
}
private void zhuce_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string oledb1 = string.Format("select count(*) from admin where yhm='{0}' ", txtzh.Text);
OleDbCommand command1 = new OleDbCommand(oledb1, lianjie.connection);
lianjie.connection.Open();
int count = (int)command1.ExecuteScalar();
if (count == 1)
{
MessageBox.Show("账号已被注册");
lianjie.connection.Close();
}
else
{
string sex = rdbn.Checked ? rdbn.Text : rdbnv.Text;
if ((txtzh.Text != "") && (txtmm.Text != "") && (txtqrmm.Text != ""))
{
if (txtmm.Text == txtqrmm.Text)
{
string oledb = string.Format("insert into admin (yhm,mm,) values ('{0}','{1}')", txtzh.Text, txtmm.Text);
string oledb2 = string.Format("insert into yhxx (xm,sfz,zhuzhi,youxiang,dianhua,qq,chushengriqi,xingbie) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',)", txtxm.Text, txtsfz.Text, txtjg.Text, txtyj.Text, txtlxfs.Text, txtqq.Text, txtcsrq.Text, sex);
try
{
OleDbCommand command = new OleDbCommand(oledb, lianjie.connection);
OleDbCommand command2 = new OleDbCommand(oledb2, lianjie.connection);
int result = command.ExecuteNonQuery();
int result2 = command2.ExecuteNonQuery();
if (result != 1 && result2!=1)
{
MessageBox.Show("注册失败");
}
else
{
MessageBox.Show("注册成功");
}
}
catch (Exception)
{
MessageBox.Show("操作数据库错误", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
lianjie.connection.Close();
}
}
}
}
}
}
}
检查错误的时候,这里没有被执行,但看着没有错误啊 ?
int result2 = command2.ExecuteNonQuery();
if (result != 1 && result2!=1)
{
MessageBox.Show("注册失败");
}
else
{
MessageBox.Show("注册成功");
}
求高手解答 |