
在数据库里转换下
convert(binary,pwd(数据库里类型))这个把类型转换为binary
一下就是把这个转回来
select convert(char(30),convert(binary,pwd(数据库里类型)) from tbuser
不知符合,请看,谢谢
是二进制字段数据(文件)
20数据库存入二进制字段数据
/
using SystemData;
using SystemIO;
using SystemDataSqlClient;
/
private string File="";
if(openFileDialog1ShowDialog()==DialogResultOK)
{
pictureBox1Image=new Bitmap(openFileDialog1FileName);
FileName=openFileDialog1FileName;
}
try{
DataSet ds=new DataSet();
sqlDataAdapter1Fill(ds,%%1); //"db"
DataTable MyTable=dsTables[0];
DataRow MyRow=MyTableRowsCount+1;
MyRow[%%2]=MyTableNewRow(); //"id"
MyRow[%%3]=%%5; //"FileName"
MyRow[%%4]=%%6; //"Description"
FileStream fs=new FileStream(FileNmae,FileModeOpenOrCreate,FileAccessRead);
byte[] MyData=new byte[fsLength];
fsRead(MyData,0,(int)fsLength);
MyRow[%%7[=MyData; //"FileData"
MyTableRowsAdd(MyRow);
sqlDataAdapter1Update(ds,%%1);
dsAcceptChanges();
//存储成功
}
catch(Exception ex)
{
//exMessageToString()
}
21数据库取出二进制字段数据
/
using SystemData;
using SystemIO;
/
private int index=1;
private SystemWindowsFormsBindingManagerBase_Bind();
private DataSet ds=new DataSet();
sqlDataAdapter1Fill(ds,%%1); //"db"
_Bind=BindingContext[ds,%%1];
textBox1DataBindingsAdd("Text",ds,"%%1%%3"); //filename
textBox2DataBindingsAdd("Text",ds,"%%1%%4"); //description
if(_BindCount!=0)
{
try{
if(pictureBox1Image!=null)
pictureBox1ImageDispose();
pictureBox1Image=null;
sqlDataAdapter1SelectCommandCommandText="Select From %%1 Where %%2="+ConvertToString(index); //id
DataSet dataSet=new DataSet();
sqlDataAdapter1Fill(dataSet,%%1);
byte[] MyData=(byte[])dataSetTables[0]Rows[0][%%5]; //"FileData"
Int32 size=MyDataGetUpperBound(0);
FileStream fs=new FileStream(%%6,FileModeOpenOrCreate,FileAccessWrtie); //"tempbmp"
fsWrite(MyData,0,size+1);
fsClose();
pictureBox1Image=new Bitmap(%%6);
}
catch(Exception ex)
{
//exMessageToString()
}
}
22批量执行SQL和存储过程
/// <summary>
/// 储存过程->删除;
/// </summary>
/// <param name="id"> </param>
/// <returns> </returns>
public DataTable GetTable(int id)
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection("server=;database=master;User id=sa;pwd=sa");
SqlCommand com = new SqlCommand("proc_Shoping", con); //连接数据库执行存储过程
comCommandType = CommandTypeStoredProcedure;
//执行存储过程
SqlDataAdapter da = new SqlDataAdapter(com);
SqlParameter param; //添加一个输入参数
param = new SqlParameter("@id", SqlDbTypeInt); //设置类型为输入类型 ,并传入参数;
paramDirection = ParameterDirectionInput;
param Value= id; //当前参数的值
paramValue =10;
comParametersAdd(param); //将设置好的sqlparameter对象添加到da中
daFill(dt);
return dt; //返回Datatable
}
这样啊,假设你有一个image字段,这么做:你用DataReader读出了这个字段,务必这样: byte[] bytes = (byte[])drGetValue(0);
StringBuilder sbu = new StringBuilder(); foreach(byte b in bytes){ sbuAppend(b);}然后您通过sbuToString();
实例:如何用C#读写数据库Image字段实例:如何用C#读写数据库Image字段 1、数据库Image字段读写文件 写文件:写文件的过程为将文件以流文件形式打开并将内容读取到一个byte数组,然后将此byte数组写入数据库的Image字段。
我就给你说一下思想啊:
把数据从数据库里读出来放在datasettable["image"]
比如说在数据库表里面你的字段是从左到右第2 个的话,在datasettable["image"]中是第一个。
下面是关键:
这个是关于picturebox的一个函数
private void showimage()
{
if thispictuebox1image!=null
thispicturebox1imagedisprose();
else
int i= thisbindingcontext[dataset,table]position();
byte[] bb=(byte[]) datasettable["image"]rows[i][1]
merrystream m= new merrystream(bb)
bitmp b= new bitemp(m)
thispicturebox1image=b
}
就是这个思想,想把数据绑定后,在把它单个读出了。
1、首先打开SQL Server后,选择数据库,点击顶部的新建查询按钮,如下图所示。
2、然后直接用sp_addtype语句进行数据类型的定义,如下图所示。
3、接下来刷新用户自定义数据类型,这次就有数据了,如下图所示。
4、接着右键数据表选择设计选项,如下图所示。
5、最后就可以在数据类型里面找到自定义的数据类型了,如下图所示。
以上就是关于vb中读取数据库中的image类型问题全部的内容,包括:vb中读取数据库中的image类型问题、取数据库image类型图片的问题、数据库IMAGE类型转换成字符串的问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)