插入錯誤,以便將新數據插入Access表。 該表有4個參數。第一個是自動編號。 這是我的代碼:使用access + asp.net/C#
public void InsertToDB(int stationId, DateTime dateTime, double temperture)
{
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database1.accdb";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = connect;
cmd.CommandText = "Insert Into TempDate (StationID,DateTime,Temper)" + "Values(@ID,@dateTime,@temper)";
cmd.Parameters.Add("@ID", OleDbType.Integer).Value = stationId;
cmd.Parameters.Add("@dateTime", OleDbType.Date).Value = dateTime;
cmd.Parameters.Add("@temper", OleDbType.Double).Value = temperture;
connect.Open();
cmd.ExecuteNonQuery(); //At this line exception is generating
connect.Close();
}// insert to db
即時得到這個錯誤:
錯誤碼= -2147217900
也許只是把該錯誤代碼到谷歌搜索?已經給出瞭如此多的結果如何解決它,例如http://stackoverflow.com/questions/13898551/i-am-getting-an-error-when-i-try-to-update-records-in-my- access-database – walther 2014-09-06 14:51:00