Insert image into cassandra blob using C#

怎甘沉沦 提交于 2019-12-24 17:27:08

问题


I am trying to insert an image into Cassandra table of column datatype blob

While inserting i get the error:

no variable alternative at input

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:


Use a parameterized query, like ( ... values(?, ?)...) and add parameters. The way you have your query, it's going to have values(1, "hello", "Array").... (or similar).

Check docs from here: https://github.com/datastax/csharp-driver



来源:https://stackoverflow.com/questions/32072373/insert-image-into-cassandra-blob-using-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!