列と画像を SQL Server 2008 データベースに挿入しようとしていますが、2 つのエラーが発生します
エラー 1
'System.IO.BinaryReader.BinaryReader(System.IO.Stream)' に最適なオーバーロードされたメソッド マッチに無効な引数がいくつかあります (行 62 列 35)エラー 2 引数 1: 'datagrid.FileStream' から 'System.IO.Stream' に変換できません (行 62 列 52)
困った…どうしよう…
try
{
byte[] img = null;
FileStream fs = new FileStream(picLoc, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
img = br.ReadBytes((int)fs.Length);
string sql = "INSERT INTO PicTable(Name,Image) VALUES(" + textBox1.Text + ",@IMG)";
if (conn.State != ConnectionState.Open)
conn.Open();
command = new SqlCommand(sql, conn);
command.Parameters.Add(new SqlParameter("@IMG", img));
int x = command.ExecuteNonQuery();
MessageBox.Show(x.ToString() + " records saved.");
conn.Close();
pictEmp.Image = null;
}
catch (Exception ex)
{
conn.Close();
MessageBox.Show(ex.Message);
}
このように見えます