【问题标题】:Insert image into cassandra blob using C#使用 C# 将图像插入 cassandra blob
【发布时间】:2015-08-18 22:29:03
【问题描述】:

我正在尝试将图像插入列数据类型为 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;
    }
  }

【问题讨论】:

    标签: c# cassandra-2.0


    【解决方案1】:

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

    从这里查看文档:https://github.com/datastax/csharp-driver

    【讨论】:

    • 非常感谢所有的帮助和时间,非常感谢。 var ps = CluSession.Prepare("插入 Product(id,name,p_image) 值 (?,?,?)"); var 语句 = ps.Bind(1, file.ToString(), MyData); CluSession.Execute(语句);
    猜你喜欢
    • 2017-03-08
    • 2016-10-31
    • 2016-01-25
    • 2015-11-03
    • 2021-02-17
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多