insert data to table based on another table C#

Posted by user1017315 on Stack Overflow See other posts from Stack Overflow or by user1017315
Published on 2011-11-27T15:00:50Z Indexed on 2011/11/27 17:50 UTC
Read the original article Hit count: 245

Filed under:
|
|
|

I wrote a code which takes some values from one table and inserts the other table in these values.(not just these values, but also these values(this values=values from the based on table))

and I get this error:

System.Data.OleDb.OleDbException (0x80040E10): value wan't given for one or more of the required parameters.`

here's the code. I don't know what i've missed.

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();
    }
  }
}

EDIT:I put a messagebox after that line:

index = dr.GetInt32(0);

to see where is the problem, and i get the error before that.i don't see the messagebox

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql