我正在尝试将 2 张图像保存到我的数据库中,但我不断收到上述错误,我尝试了很多但无法解决它。
string fileName = "";
string fileName2 = "";
private void SaveReq()
{
try
{
byte[] img = null;
byte[] img2 = null;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
FileStream fs2 = new FileStream(fileName2, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
BinaryReader br2 = new BinaryReader(fs2);
img = br.ReadBytes((int)fs.Length);
img2 = br2.ReadBytes((int)fs2.Length);
SqlConnection CN = new SqlConnection(mysql.CON.ConnectionString);
string Query = "insert into BUILD_LIC (ID,KROKY,KROKY_3AM) values('" + txtID.Text + "',@KROKY,@KROKY_3AM)";
CN.Open();
mysql.COMMAND = new SqlCommand(Query, CN);
mysql.COMMAND.Parameters.Add(new SqlParameter("@KROKY", img));
mysql.COMMAND.Parameters.Add(new SqlParameter("@KROKY_3AM", img2));
mysql.COMMAND.ExecuteNonQuery();
CN.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
如果我删除其中一个文件流(fs,fs2),则代码工作并保存图像仅用于一个,我想保存这两个图像,您能否通过更正我的代码来告诉我如何做到这一点