我正在创建一个数据库应用程序;带有 MS Access 数据库文件。发生的事情是正确插入所有内容,但不是电话号码。输入电话号码时,我正在工作的应用程序会引发异常。
我已经仔细检查了我的编码和我的数据库,但无法弄清楚为什么会导致这个问题。这是代码的一部分。
private void btn_Save_Click(object sender, EventArgs e)
{
{
try
{
OleDbCommand DBcmd = new OleDbCommand();
DBcmd.CommandType = CommandType.Text;
DBcmd.CommandText = "INSERT INTO tbl_ClientInfo (FirstName, LastName, Address, ZipCode, City, State, Country, Language, PhoneNr, MobileNr)" + "VALUES (@FirstName, @LastName, @Address, @ZipCode, @City, @State, @Country, @Language, @PhoneNr, @MobileNr)";
DBcmd.Parameters.AddWithValue("@FirstName", txt_FirstName.Text);
DBcmd.Parameters.AddWithValue("@LastName", txt_LastName.Text);
DBcmd.Parameters.AddWithValue("@Address", txt_Address.Text);
DBcmd.Parameters.AddWithValue("@ZipCode", txt_ZipCode.Text);
DBcmd.Parameters.AddWithValue("@City", txt_City.Text);
DBcmd.Parameters.AddWithValue("@State", txt_State.Text);
DBcmd.Parameters.AddWithValue("@Country", ComboBox_Countries.SelectedItem);
DBcmd.Parameters.AddWithValue("@Language", comboBox_Languages.SelectedItem);
DBcmd.Parameters.AddWithValue("@PhoneNr", txt_PhoneNr.Text);
DBcmd.Parameters.AddWithValue("@MobileNr", txt_MobileNr.Text);
DBcmd.Connection = DBconnection;
DBconnection.Open();
DBcmd.ExecuteNonQuery();
DBconnection.Close();
catch (Exception ex)
{
System.IO.StreamWriter file = new System.IO.StreamWriter(@"d:\test.txt");
file.WriteLine(ex);
file.Close();
}
}
}
提前致谢