本文介绍了使用C#Windows应用程序将图像保存到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

需要帮助从C#Windows应用程序上传图片.不幸的是我..我有错误->字符串或二进制数据将被截断.该语句已终止

试试
{
//将图像字节读入字节数组
byte [] imageSampleData = ReadImageToBytes(txtImagePath.Text);

//初始化SQL Server连接
SqlConnection con =新的SqlConnection(txtConnectionString.Text);

//设置插入查询
字符串查询="INSERT INTO p(ee,i1)values(@ ee,@ i1)";

//初始化SqlCommand对象以进行插入.
SqlCommand cmd =新的SqlCommand(query,con);

cmd.Parameters.Add(新SqlParameter("@ ee",
(object)txtImagePath.Text));

cmd.Parameters.Add(新SqlParameter("@ i1",
(object)imageSampleData));

//打开连接并执行插入查询.
con.Open();
cmd.ExecuteNonQuery(); --->错误发生在这里!
con.Close();


请帮助我.

Hi everyone..

Need help to upload picture from C# windows application. Unlucky me.. ive got error --> string or binary data would be truncated.the statement has been terminated

try
{
//Read Image Bytes into a byte array
byte[] imageSampleData = ReadImageToBytes(txtImagePath.Text);

//Initialize SQL Server Connection
SqlConnection con = new SqlConnection(txtConnectionString.Text);

//Set insert query
string query = "INSERT INTO p (ee,i1) values(@ee,@i1)";

//Initialize SqlCommand object for insert.
SqlCommand cmd = new SqlCommand(query, con);

cmd.Parameters.Add(new SqlParameter("@ee",
(object)txtImagePath.Text));

cmd.Parameters.Add(new SqlParameter("@i1",
(object)imageSampleData));

//Open connection and execute insert query.
con.Open();
cmd.ExecuteNonQuery();---> error occur here!
con.Close();


Please help me.

推荐答案



这篇关于使用C#Windows应用程序将图像保存到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:04