当我想将文本框中的值插入到我的访问数据库时,我遇到了问题! 当我想保存时,我得到了这个错误(“条件表达式中的数据类型不匹配”) 代码:
string conString = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=C:\\Users\\Simon\\Desktop\\test5\\test5\\test5\\save.mdb";
OleDbConnection empConnection = new OleDbConnection(conString);
string insertStatement = "INSERT INTO aktivnosti_save "
+ "([ID_uporabnika],[ID_aktivnosti],[kalorij]) "
+ "VALUES (@ID_uporabnika,@ID_aktivnosti,@kalorij)";
OleDbCommand insertCommand = new OleDbCommand(insertStatement, empConnection);
insertCommand.Parameters.Add("@ID_uporabnika", OleDbType.Char).Value = textBox3.Text;
insertCommand.Parameters.Add("@ID_zivila", OleDbType.Char).Value = iDTextBox.Text;
insertCommand.Parameters.Add("@kalorij", OleDbType.Char).Value = textBox2.Text;
empConnection.Open();
try
{
int count = insertCommand.ExecuteNonQuery();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
empConnection.Close();
textBox1.Clear();
textBox2.Clear();
}
}
答案 0 :(得分:-1)
您可以在(string insertStatement =)中使用String Concatenation而不是
insertCommand.Parameters.Add("@ID_uporabnika", OleDbType.Char).Value = textBox3.Text;
你可以写成例子:
string insertStatment = "INSERT INTO aktivnosti_save "
+ "([ID_uporabnika],[ID_aktivnosti],[kalorij]) "
+ "VALUES ('"+textbox1.text+"','"+textbox2.text+"','"+textbox3.text+"')";
尝试这个,让我知道任何进一步的问题。你是我们