使用C#将图像插入到cassandra blob中

时间:2015-08-18 12:25:09

标签: c# cassandra-2.0

我正在尝试将图像插入到列数据类型blob

的Cassandra表中

插入时我收到错误:

  

输入

时没有变量替代
ISession CluSession = cluster.Connect("dbs");
MemoryStream ms = new MemoryStream();
OpenFileDialog f = new OpenFileDialog();
f.InitialDirectory = @"H:\MobilePics_sufian\";
f.Filter = "All Files |*.*|JPEGs|*.jpg|Bitmaps|*.bmp|GIFs|*.gif";
            f.Multiselect = true;

DialogResult dr = f.ShowDialog();
int i = 0;
 if (dr == System.Windows.Forms.DialogResult.OK)
 {
   foreach(string file in f.FileNames)
   {
    i = 1;
    lstimage.Items.Add(file.ToString());
    FileStream fs = new FileStream(file.ToString(), FileMode.OpenOrCreate,  FileAccess.Read);
    byte[] MyData = new byte[fs.Length];
    fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
    CluSession.Execute("insert into Product1(id,name,p_image) values (" + i + "," + "hello" + "," + MyData.ToArray() + ")");

    i = i + 1;
    }
  }

1 个答案:

答案 0 :(得分:2)

使用参数化查询,例如(... values(?,?)...)并添加参数。你的查询方式,它将具有值(1,"你好","数组")....(或类似的)。

点击此处的文档:https://github.com/datastax/csharp-driver