System.IO.Stream imgdatastream=this.myFile.PostedFile.InputStream; int imgDataLen=this.myFile.PostedFile.ContentLength; string imgType=this.myFile.PostedFile.ContentType; string imgName=this.myFile.PostedFile.FileName;
int iPos=imgName.LastIndexOf(@"\"); imgName=imgName.Substring(iPos+1,imgName.Length-iPos-1);
byte[] imgData=new byte[imgDataLen];imgdatastream.Read(imgData,0,imgDataLen);下面是一段VB的代码,参考一下就行了 Dim command As SqlCommand = New SqlCommand("INSERT INTO ImageStore(imgtype,imgdata) values(@imgtype,@imgdata )", connection) //插入参数 Dim paramData As SqlParameter = New SqlParameter("@imgdata", SqlDbType.Image) paramData.Value = imgData command.Parameters.Add(paramData)
FileStream ImageFile = new FileStream( "图片",FileMode.Open ); byte bytes = new byte[(int)ImageFile .Length]; ImageFile .Read( bytes,0,bytes.Length); if (intFile>0) { conn = new OleDbConnection( this.strSqlConn ); this.strSqlCmd = "Insert into table (Img) values (@Image)" ; cmd = new OleDbCommand( strSqlCmd,conn ); conn.Open(); cmd.Parameters.Add("@Image",OleDbType.Binary);cmd.Parameters["@Image"].Value = bytes cmd.ExecuteNonQuery(); }
int imgDataLen=this.myFile.PostedFile.ContentLength;
string imgType=this.myFile.PostedFile.ContentType;
string imgName=this.myFile.PostedFile.FileName;
int iPos=imgName.LastIndexOf(@"\");
imgName=imgName.Substring(iPos+1,imgName.Length-iPos-1);
byte[] imgData=new byte[imgDataLen];imgdatastream.Read(imgData,0,imgDataLen);下面是一段VB的代码,参考一下就行了 Dim command As SqlCommand = New SqlCommand("INSERT INTO ImageStore(imgtype,imgdata) values(@imgtype,@imgdata )", connection) //插入参数
Dim paramData As SqlParameter = New SqlParameter("@imgdata", SqlDbType.Image)
paramData.Value = imgData
command.Parameters.Add(paramData)
byte bytes = new byte[(int)ImageFile .Length];
ImageFile .Read( bytes,0,bytes.Length);
if (intFile>0)
{
conn = new OleDbConnection( this.strSqlConn );
this.strSqlCmd = "Insert into table (Img) values (@Image)" ;
cmd = new OleDbCommand( strSqlCmd,conn );
conn.Open();
cmd.Parameters.Add("@Image",OleDbType.Binary);cmd.Parameters["@Image"].Value = bytes cmd.ExecuteNonQuery();
}