请大侠指教,我如何用sql写,将二进制数组存入字段类型为Image的字段中,sqlserver2008环境
public static void updateState(long id, byte[] tel)
{
string strUpdate = "update T_Res set Tel=" +tel + ",Hobbies=5 where ID=" + id;
public static void updateState(long id, byte[] tel)
{
string strUpdate = "update T_Res set Tel=" +tel + ",Hobbies=5 where ID=" + id;
解决方案 »
- 求大神指导 .net怎么在网页中播放视频文件呢 最好友源码啊 着急用啊
- 高分提问:asp.net能否用J#语言开发?
- 急...为listbox控件绑定数据源,运行结果的网页上却没有任何结果,为什么呢?谢谢大侠,在线等.........
- 求解URLRewriter的问题,请大家帮帮忙,知道的麻烦告诉我一下!
- 急!急!急!为自定义控件加事件后,出错项目名.命名空间 中不存在类型名称"类名"
- 需要高手才能解决的问题,SP1234等高手进来帮看看
- executescalar连接的当前状态为已连接
- 高分求助ASP.NET怎样与WINFORM进行通信
- 为什么出现Compiler Error Message: CS1010: Newline in constant ??
- 求教如何实现web窗体从asp页面接收数据?急!!!
- 2种创建对象的方法,他们的性能区别很大吗?
- 下拉多选框无法触发事件
把tel给一个参数赋值即可。http://www.cnblogs.com/cancer_xu/archive/2009/09/13/1565845.html
try
{
SqlParameter sp = new SqlParameter("@tel",tel,SqlDbType.Image);
SqlParameter sp1 = new SqlParameter("@id", tel, SqlDbType.BigInt);
mycon = GetCon();
mycon.Open();
mycom = new SqlCommand(strUpdate, mycon);
mycom.ExecuteNonQuery();
}我这样写对吗
--创建表
create table test(col varbinary(4000))
go --创建存储过程
create procedure sp_savaBinary(@binary varbinary(4000))
as
insert into test values(@binary)
go --调用存储过程插入数据
declare @binary varbinary(4000)
set @binary = cast( '12sfasfasfasf ' as varbinary(4000))
exec sp_savaBinary @binary
//将流转换成数组
byte[] bWrite = mstream.ToArray();
//将数组写入数据库
System.Data.SqlClient.SqlParameter[] pram ={
sqlHelper.MakeInParam("@XX",System.Data.SqlDbType.Image)
};
pram[0].Value = bWrite;
//执行SQL
//xxxxxxxxxx("insert into XXX (XX) values (@XX)", pram);
{ string strUpdate = string.Format("update T_Resume set Tel=@tel,Hobbies=5 where ID=@id");
try
{
mycon = GetCon();
mycon.Open();
mycom = new SqlCommand(strUpdate, mycon);
mycom.Parameters.Add("@tel", SqlDbType.Image);
mycom.Parameters["@tel"] = tel;
mycom.Parameters.Add("@id", SqlDbType.BigInt);
mycom.Parameters["@id"] =id;
mycom.ExecuteNonQuery();
}
catch (Exception exe)
{
Console.Write(exe.Message);
}
}