我无法保存文件。请帮忙。这是我的代码
private void cmdsave_Click(object sender, EventArgs e)
{
//x = 0;
con();
sqlcommand.CommandText = "SELECT * FROM tblname WHERE PCode = '" + txtlname.Text + "' AND PName = '" + txtfname.Text + "' AND Quantity = '" + txtmname.Text + "' AND Section = '" + textBox2.Text + "' ";
sqlcommand.Connection = connect;
OleDbDataReader reader = sqlcommand.ExecuteReader();
while (reader.Read())
{x++;}
if (x != 0)
{
MessageBox.Show("Duplicate record(s) found...");
}
else
{
if (mode == "a")
{
con();
sqlcommand.CommandText = "INSERT INTO tblname (PCode, PName, Quantity, Section) VALUES ('" + txtlname.Text + "', '" + txtfname.Text + "', '" + txtmname.Text + "', '" + textBox2.Text + "') ";
sqlcommand.Connection = connect;
reader = sqlcommand.ExecuteReader();
MessageBox.Show("Record(s) Saved", "Sample");
}
else if (mode == "e")
{
con();
sqlcommand.CommandText = "UPDATE tblname SET PCode = '" + txtlname.Text + "', PName = '" + txtfname.Text + "', Quantity = '" + txtmname.Text + "' , Section = '" + textBox2.Text + "' WHERE ID = " + idholder + " ";
sqlcommand.Connection = connect;
reader = sqlcommand.ExecuteReader();
MessageBox.Show("Record(s) Updated", "Sample");
}
}
connect.Close();
idholder = "";
cncel();
}
我只是添加了部分(textBox2)。在添加这些代码之前,程序运行正确。