再插入时,“System.Data.SqlClient.SqlException”类型的第一次机会异常在 System.Data.dll 中发生
用相同语句,其他地方插入没有问题只有这里有privatevoidbutton2_Click(objectsender,EventArgse){StringDbConnec...
用相同语句,其他地方插入没有问题 只有这里有
private void button2_Click(object sender, EventArgs e)
{
String DbConnectstr = "Server=.;Database=售后服务;Uid=sa;pwd=8647698";
SqlConnection MyConnection = new SqlConnection(DbConnectstr);
string MyInsert;
MyInsert = "insert into 报修单 ([报修单号],[维修人员],[维修人电话],[维修状况],[报修公司],[报修日期],[维修人员ID],[维修人员所在地])values('" + textBox4.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox7.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox1.Text + "','" + textBox8.Text + "')";
SqlCommand MyCommand = new SqlCommand(MyInsert, MyConnection);
try//异常处理
{
MyConnection.Open();
MyCommand.ExecuteNonQuery();
MyConnection.Close();
MessageBox.Show("录入成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception)
{
MessageBox.Show("录入失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
} 展开
private void button2_Click(object sender, EventArgs e)
{
String DbConnectstr = "Server=.;Database=售后服务;Uid=sa;pwd=8647698";
SqlConnection MyConnection = new SqlConnection(DbConnectstr);
string MyInsert;
MyInsert = "insert into 报修单 ([报修单号],[维修人员],[维修人电话],[维修状况],[报修公司],[报修日期],[维修人员ID],[维修人员所在地])values('" + textBox4.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox7.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox1.Text + "','" + textBox8.Text + "')";
SqlCommand MyCommand = new SqlCommand(MyInsert, MyConnection);
try//异常处理
{
MyConnection.Open();
MyCommand.ExecuteNonQuery();
MyConnection.Close();
MessageBox.Show("录入成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception)
{
MessageBox.Show("录入失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询