String query = "";
string constr = ConfigurationSettings.AppSettings["MySQLConnectionStringForIMS"];
using (MySqlConnection con = new MySqlConnection(constr))
{
//string query = "INSERT INTO user(name, files,contentType) VALUES (@name,@files,@contentType)";
if (update == "mainSec")
{
query = "update main_section set contentType=@contentType,fileData=@fileData,fileNameAfterUploading=@fname,haveDir=@dir where id=@id";
}
else
{
query = "update sub_section set subContentType=@contentType,subFileData=@fileData,fileNameAfterUploading=@fname,haveDir=@dir where MainSecId=@id and id=@subId";
}
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@contentType", contentType);
cmd.Parameters.AddWithValue("@fileData", data);
cmd.Parameters.AddWithValue("@fname", filename);
cmd.Parameters.AddWithValue("@dir", 1);
cmd.Parameters.AddWithValue("@id", mainId);
if (update == "subSec")
{
cmd.Parameters.AddWithValue("@subId", subId);
}
con.Open();
int st = cmd.ExecuteNonQuery();
if (st == 1)
{
//Uri uri = new Uri(url, UriKind.Absolute);
//System.IO.File.Delete(uri.LocalPath);
}
con.Close();
}
}
We are using MySql.Data.dll version 6.9.5.0.
This fails with the error: mysql Fatal error encountered during command execution. Any ideas on why this would fail?
if (update == "subSec")toif (update != "mainSec")in order to ensure the param binding is in synch with the correct query defined above.