我写了一些代码,从一个表中取出一些值,并插入其他表中的值(不仅仅是这些值,还包括这些值(这个值=基于上表))基于另一个表插入数据到表#C#
,我得到这个错误:
System.Data.OleDb.OleDbException (0x80040E10): value wan't given for one or more of the required parameters.`
这里的代码。我不知道我错过了什么。
string selectedItem = comboBox1.SelectedItem.ToString();
Codons cdn = new Codons(selectedItem);
string codon1;
int index;
if (this.i != this.counter)
{
//take from the DataBase the matching codonsCodon1 to codonsFullName
codon1 = cdn.GetCodon1();
//take the serialnumber of the last protein
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
string last= "SELECT proInfoSerialNum FROM tblProInfo WHERE proInfoScienceName = "+this.name ;
OleDbCommand getSerial = new OleDbCommand(last, conn);
OleDbDataReader dr = getSerial.ExecuteReader();
dr.Read();
index = dr.GetInt32(0);
//add the amino acid to tblOrderAA
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
string insertCommand = "INSERT INTO tblOrderAA(orderAASerialPro, orderAACodon1) "
+ " values (?, ?)";
using (OleDbCommand command = new OleDbCommand(insertCommand, connection))
{
connection.Open();
command.Parameters.AddWithValue("orderAASerialPro", index);
command.Parameters.AddWithValue("orderAACodon1", codon1);
command.ExecuteNonQuery();
}
}
}
编辑:我把一个消息那行之后:
index = dr.GetInt32(0);
,看看问题出在哪里了,我之前得到的错误。我没有看到在MessageBox
钢不起作用。 – user1017315
@ user1017315我复制了你的代码,那就是错误发生的地方。代码中的哪一行实际上会产生错误? – LarsTech
**请参阅我的编辑** – user1017315