INSERT INTO 表(字段1,字段2) VALUES(值一,byte[] a) /这种语句是否能把byte[]类型的数据插入到一个binary字段。 不能直接这么写, 用cmd.Parameters.Add("@Image", SqlDbType.Binary, bytes.Length).Value = bytes; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上传图片例子public void Button_Submit(Object o, EventArgs e){ HttpPostedFile upFile = up_file.PostedFile; int iFileLength = upFile.ContentLength; try { if(iFileLength == 0) { txtMess.Text = "请选择要上传的文件!"; } else { Byte[] FileByteArray = new Byte[iFileLength]; Stream StreamObject = upFile.InputStream; StreamObject.Read(FileByteArray, 0, iFileLength); SqlConnection conn = new SqlConnection("server=yy;uid=sa;pwd=;database=pany"); string sql = "insert into t_imgs (imgData, type, description, imgSize) values " + "(@Image, @ContentType, @ImageDescription, @ImgSize)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add("@Image", SqlDbType.Binary, iFileLength).Value = FileByteArray; cmd.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = upFile.ContentType; cmd.Parameters.Add("@ImageDescription", SqlDbType.VarChar, 200).Value = txtDesc.Text; cmd.Parameters.Add("@ImgSize", SqlDbType.BigInt, 8).Value = upFile.ContentLength; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); txtDesc.Text = ""; txtMess.Text = "OK!你已经成功上传了类型的文件"; } } catch(Exception ex) { txtMess.Text = ex.Message.ToString(); }} asp.net如何向有自动编号的Access数据库数据表插入数据? 初学者 gridview 怎样显示两个表的数据? 请教一个关于文件下载的问题 拼音 如何在gridview中把某一个字段做成数据绑定? 路过有分''''''''''''''''''''''''''''''' ASP.NET程序中常用的三十三种代码(经典阿) datagrid一个模板列绑定多个值,如何取得每一个值在后台代码中! 如何动态的创建web控件页 请教一个TextBox的属性的问题 关于数据库信任连接的问题。
{
HttpPostedFile upFile = up_file.PostedFile;
int iFileLength = upFile.ContentLength;
try
{
if(iFileLength == 0)
{
txtMess.Text = "请选择要上传的文件!";
}
else
{
Byte[] FileByteArray = new Byte[iFileLength];
Stream StreamObject = upFile.InputStream;
StreamObject.Read(FileByteArray, 0, iFileLength);
SqlConnection conn = new SqlConnection("server=yy;uid=sa;pwd=;database=pany");
string sql = "insert into t_imgs (imgData, type, description, imgSize) values "
+ "(@Image, @ContentType, @ImageDescription, @ImgSize)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@Image", SqlDbType.Binary, iFileLength).Value = FileByteArray;
cmd.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = upFile.ContentType;
cmd.Parameters.Add("@ImageDescription", SqlDbType.VarChar, 200).Value = txtDesc.Text;
cmd.Parameters.Add("@ImgSize", SqlDbType.BigInt, 8).Value = upFile.ContentLength;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
txtDesc.Text = "";
txtMess.Text = "OK!你已经成功上传了类型的文件";
}
}
catch(Exception ex)
{
txtMess.Text = ex.Message.ToString();
}
}