0

我试图在将记录写入文件之前查看表中是否存在记录,但我一直收到错误

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 + "");
}
4

1 回答 1

0

谢谢我通过更改 .ExecuteReader(); 解决了我的问题 到 .ExecuteNonQuery();

它现在检查它是否在数据库中,如果不是,则将信息输入到表中。

于 2013-07-30T14:51:56.820 回答