使用C#将图像插入cassandra blob [英] Insert image into cassandra blob using C#

查看:249
本文介绍了使用C#将图像插入cassandra blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

的Cassandra表中错误:

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;
    }
  }


推荐答案

使用参数化查询,例如(... values(?,?)...)并添加参数。您查询的方式将是值(1, hello, Array)...(或类似值)。

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).

从中检查文档此处: https://github.com/datastax/csharp-driver

这篇关于使用C#将图像插入cassandra blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆