我正在尝试查看表中是否存在记录,然后才将其写入文件但我一直收到错误
string InformationCheck = "Select FName,LName from Customer where FName ='" + this.f_Name.Text + "' and LName = '" + l_Name.Text + "'";
OleDbCommand InfoCheck = new OleDbCommand(InformationCheck, conn);
String strResult = String.Empty;
try
{
conn.Open();
strResult = (String)InfoCheck.ExecuteScalar();
if (strResult.Length == 0)
{
MessageBox.Show("Dose Not Exist");
AddInfo.ExecuteReader();
conn.Close();
this.Hide();
f1.Show();
}
else
{
MessageBox.Show("Exists");
}
}
catch (Exception ex)
{
MessageBox.Show("" + ex + "");
}
答案 0 :(得分:0)
谢谢我通过更改.ExecuteReader()解决了我的问题。 to .ExecuteNonQuery();
现在检查它是否在数据库中,如果不是信息输入表中。