当我尝试在我的一个表中插入数据时出现以下错误“INSERT INTO查询不能包含多值字段”,其他表工作正常。
我正在使用Access 2010数据库,字段类型是文本,日期,数字,自动编号,货币。 我想念一下吗?
public void CreateNewSystemWithDefaultValues(String IP)
{
String[] Convert = NetworkInformation.GETDNSFfromIP(IP).Split('.');
DataTable Data = SystemsAccessDB.GETAllDataFromDBWithOption("Systems", "Where 1 = 2");
DataRow DataR;
DataR = Data.NewRow();
DataR["SystemName"] = Convert[0];
DataR["SystemSerialNumber"] = @"n/a";
DataR["SystemCreationDate"] = System.DateTime.Now.Date;
DataR["SystemIPAdress"] = IP;
DataR["SystemDRACAdress"] = @"n/a";
DataR["SystemState"] = "Unknown";
DataR["SystemNIC"] = @"n/a";
DataR["SystemHDDController"] = @"n/a";
DataR["SystemServiceTag"] = @"n/a";
DataR["SystemWikiURL"] = @"https://wikiurl";
DataR["SystemInstallationMedia"] = @"\\Networkpath\";
DataR["SystemMonitoring"] = @"n/a";
DataR["SystemTypeID"] = 6;
DataR["SystemsCPUID"] = 6;
DataR["SystemsMemoryID"] = 6;
DataR["SystemsDowntimeID"] = 9;
DataR["SystemOSID"] = 9;
DataR["SystemLocationID"] = 6;
DataR["SystemContactDataIDHardware"] = 1;
Data.Rows.Add(DataR);
SystemsAccessDB.ADDDataToDB("Systems", Data);
}
public static void ADDDataToDB(String Table, DataTable Data)
{
using (OleDbConnection DBConnection = new OleDbConnection(GetConnectionString()))
{
OleDbDataAdapter DataAdapter = new OleDbDataAdapter();
DataAdapter.SelectCommand = new OleDbCommand("SELECT * FROM "+Table+"", DBConnection);
OleDbCommandBuilder CommandBuilder = new OleDbCommandBuilder(DataAdapter);
CommandBuilder.GetInsertCommand();
try
{
DBConnection.Open();
DataAdapter.Update(Data);
}
catch (OleDbException e)
{
MessageBox.Show(e.Message);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}