Update an item in MySQL with VS2003
-
I try to use ODBC to update an item in MySQL table "my_status", but it doesn't work. Seems the data can be loaded to the dataset, but how to write it back to the data sourse? Is there anybody can give me some ideas or samples on how to do this? Here is my code: /////connect to the database with DataSet String* strSql = "SELECT * FROM my_status"; OdbcDataAdapter* da = new OdbcDataAdapter(strSql,MYSQLCONN); OdbcCommandBuilder* custCB = new OdbcCommandBuilder(da); OdbcCommand* cmd; cmd = new OdbcCommand("Select * from my_status", MyConn); da->SelectCommand = cmd; DataSet* wrbtDS = new DataSet(); da->Fill(wrbtDS, "my_status"); DataRow* cRow = wrbtDS->Tables->Item["my_status"]->Rows->Item[0]; //// load the image into the dataset String * FILE_NAME = "Solid.jpg"; // for inserting a image file FileStream* fs = new FileStream(FILE_NAME, FileMode::Open, FileAccess::Read); Int16 imglen = (int)fs->Length; Byte buffer[] = new Byte[imglen]; fs->Read(buffer,0,buffer->Length); cRow->Item["image"] = buffer; /* until here the item["image"] is changed and shows in DataSet, but how to update the data source with this updated DataSet??????? The following code doesn't work and how to figure it out?*/ wrbtDS->Tables->Item["my_status"]->Rows->Item[0]->AcceptChanges(); da->Update(wrbtDS, "my_status"); Thanks a lot! Kevin