0

列と画像を 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);
        }

このように見えます

ここに画像の説明を入力

4

1 に答える 1

0

エラーに基づいて、FileStream は System.IO 名前空間からのものではなく、dataGrid 名前空間からのものです。

FileStream を完全に修飾すると、問題が解決するはずです。

System.IO.FileStream fs = new System.IO.FileStream(picLoc, FileMode.Open, FileAccess.Read);
于 2013-07-04T18:49:00.377 に答える