The code is below. in my code I updating existing row(from existing table) that the program get all the updated values from textBoxes. there is at the end(the last column)of the table autoNumber field which is named as "codonsAutoNum"
I don't know how to get the value (autonumber value) from the databese. I need the value in the position (in the code) where there is '??'.
thank you all for your help!
the code:
private void update_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
OleDbConnection myConnection = new OleDbConnection(connectionString);
string myInsertQuery =(String.Format("UPDATE tblCodons SET codonsCodon1='{0}', codonsCodon3='{1}', " +
"codonsTriplet1='{2}', codonsTriplet2='{3}', codonsTriplet3='{4}', codonsTriplet4='{5}', " +
"codonsTriplet5='{6}', codonsTriplet6='{7}', codonsFullName='{8}'" +
" WHERE codonsAutoNum='{9}'",codon1.Text, codon3.Text ,triplet1.Text, triplet2.Text,
triplet3.Text, triplet4.Text, triplet5.Text, triplet6.Text,
fullName.Text,??));
OleDbCommand myCommand = new OleDbCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
EDIT: it got really confused.How does my code is suppoused to be seemed? Where do i need to put the "SELECT @@identity"?and i don't understand why can't I just take the value? (i need it as index to the selected row to figure where the update is. it worked well when i id this(below) but it didn't allowed me to change the fullname field..there is a better solution than the autonumber column?
private void update_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
OleDbConnection myConnection = new OleDbConnection(connectionString);
string myInsertQuery =(String.Format("UPDATE tblCodons SET codonsCodon1='{0}', codonsCodon3='{1}', " +
"codonsTriplet1='{2}', codonsTriplet2='{3}', codonsTriplet3='{4}', codonsTriplet4='{5}', " +
"codonsTriplet5='{6}', codonsTriplet6='{7}', codonsFullName='{8}'" +
" WHERE codonsFullName = {9}",codon1.Text, codon3.Text ,triplet1.Text, triplet2.Text,
triplet3.Text, triplet4.Text, triplet5.Text, triplet6.Text,
fullName.Text,this.name));
OleDbCommand myCommand = new OleDbCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
this.tblCodonsTableAdapter.Fill(this.myProjectDataSet.tblCodons);
name= saved value of fullname, in each clicking the value chages
one more Ques. I tried to do the same with e.Row (which i saved in each clicking in the table) and i get an error "System.Data.OleDb.OleDbException (0x80004005): can caue a duplicated values on the index,or on the mainKey or in the relationship"