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();
}
}
我们正在使用的是MySql.Data.dll版本6.9.5.0。
这会导致错误:mysql执行命令期间遇到严重错误。你有任何想法为什么会失败?
if (update == "subSec")
更改为if (update != "mainSec")
,以确保参数绑定与上面定义的正确查询同步。 - StuartLC