That update SQL seems to be malformed.
What is the name of the table it is updating?
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
OK. Unless you're doing something [ special / unorthodox / proprietary ],
your SQL should start out like:
string updatessql =
string.Format("update component_material_id set GROUPING='{0}'",
this.RadioButtonList1.SelectedValue.ToString());
Are you also attempting to do a sub-select?
Anyway: Afterward, you control the commit by either executing and actual Commit on a transaction you create OR by closing the connection to the database. -- but not inside the SQL.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
what is your connection string
mani-hellboy
Junior Poster in Training
69 posts since Feb 2012
Reputation Points: 0
Solved Threads: 7
What I'm specifically talking about is removing the excess code from your SQL statement (that tries to do multiple things) and just concentrate on the update.
Let the framework handle the commit (outside of the SQL)
Even though you're using SQL Server Express, this will translate.
Example:
public static bool StoreToMySql(CSomeDataMaster master, ref string strError)
{
bool blnRetVal = true;
try
{
using (MySqlConnection conn = new MySqlConnection(CDB_X.csb.ToString()))
{
conn.Open();
MySqlTransaction trans = conn.BeginTransaction();
MySqlCommand cmd = new MySqlCommand("DELETE FROM SOME_TABLE", conn, trans);
cmd.ExecuteNonQuery();
string strSQL =
"insert into SOME_TABLE (FAKE_COLUMN1, FAKE_COLUMN2) " +
"VALUES(?pFAKE_VALUE1, ?pFAKE_VALUE2)";
cmd = new MySqlCommand(strSQL, conn, trans);
InitParams(cmd); // my method that inits params (not necessary for this example)
foreach (CSomeData dataObj in master)
{
FillParams(cmd, dataObj); // my method that fills parameters (not necessary for this example)
cmd.ExecuteNonQuery();
}
trans.Commit(); // <<--ONE commit at the end of all grouped actions
conn.Close();
}
}
catch (Exception exc)
{
blnRetVal = false;
strError = exc.Message;
}
return blnRetVal;
}
Also, you might not need to call commit at all.
If you are closing the connection after your command, it will commit.
In either case, remove the COMMIT and also the END from your SQL string.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402