用ado.net对word,excel进行存取
来源:网络整理 责任编辑:栏目编辑 发表时间:2013-07-02 04:32 点击:次
blob表
3 id int 4 0
0 name char 50 1
0 blob image 16 1
0 type char 60 1
saveFile.aspx.cs
private void Button1_Click(object sender, System.EventArgs e)
{
Stream imgdatastream = File1.PostedFile.InputStream;
int imgdatalen = File1.PostedFile.ContentLength;
string imgtype = File1.PostedFile.ContentType;
string name = this.getFileNameByURL(this.File1.PostedFile.FileName);
byte[] imgdata = new byte[imgdatalen];
int n = imgdatastream.Read(imgdata,0,imgdatalen);
string connstr = "workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand("INSERT INTO blob(name,type,blob) VALUES ( @imgtitle, @type,@blob )", connection );
SqlParameter paramTitle = new SqlParameter("@imgtitle", SqlDbType.VarChar,50 );
paramTitle.Value = name;
command.Parameters.Add(paramTitle);
SqlParameter paramData = new SqlParameter( "@blob", SqlDbType.Image );
paramData.Value = imgdata;
command.Parameters.Add( paramData );
SqlParameter paramType = new SqlParameter( "@type", SqlDbType.VarChar,50 );
paramType.Value = imgtype;
command.Parameters.Add( paramType );
wztj.debug.TestSQL.TraceErrorSql("INSERT INTO blob(name,type,blob) VALUES ( @imgtitle, @type,@blob )",command.Parameters);
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
}
listFile.aspx//这个东西主要用来列表,把已经有的东西列出来
<asp:HyperLinkColumn DataNavigateUrlField="id" HeaderText="产品名称" DataNavigateUrlFormatString="./getFile.aspx?ID={0}" DataTextField="name" DataTextFormatString="{0}" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="160px">
listFile.aspx.cs
string connstr="workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand("select * from blob", connection );
connection.Open();
SqlDataAdapter adaptor = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adaptor.Fill(ds,"blob");
connection.Close();
this.DataGrid1.DataSource=ds.Tables["blob"].DefaultView;
this.DataGrid1.DataBind();
getFile.aspx.cs//这个文件比较重要负责把村道数据库里面的文件,按照格式,按照名称,给传输出来
private void Page_Load(object sender, System.EventArgs e)
{
string imgid =this.Request.QueryString.Get("ID");
//Request.QueryString["imgid"];
string connstr="workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
string sql="SELECT name,blob, type FROM blob WHERE id = " + imgid;
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
Response.Clear();
Response.Buffer= true;
Response.
3 id int 4 0
0 name char 50 1
0 blob image 16 1
0 type char 60 1
saveFile.aspx.cs
private void Button1_Click(object sender, System.EventArgs e)
{
Stream imgdatastream = File1.PostedFile.InputStream;
int imgdatalen = File1.PostedFile.ContentLength;
string imgtype = File1.PostedFile.ContentType;
string name = this.getFileNameByURL(this.File1.PostedFile.FileName);
byte[] imgdata = new byte[imgdatalen];
int n = imgdatastream.Read(imgdata,0,imgdatalen);
string connstr = "workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand("INSERT INTO blob(name,type,blob) VALUES ( @imgtitle, @type,@blob )", connection );
SqlParameter paramTitle = new SqlParameter("@imgtitle", SqlDbType.VarChar,50 );
paramTitle.Value = name;
command.Parameters.Add(paramTitle);
SqlParameter paramData = new SqlParameter( "@blob", SqlDbType.Image );
paramData.Value = imgdata;
command.Parameters.Add( paramData );
SqlParameter paramType = new SqlParameter( "@type", SqlDbType.VarChar,50 );
paramType.Value = imgtype;
command.Parameters.Add( paramType );
wztj.debug.TestSQL.TraceErrorSql("INSERT INTO blob(name,type,blob) VALUES ( @imgtitle, @type,@blob )",command.Parameters);
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
}
listFile.aspx//这个东西主要用来列表,把已经有的东西列出来
<asp:HyperLinkColumn DataNavigateUrlField="id" HeaderText="产品名称" DataNavigateUrlFormatString="./getFile.aspx?ID={0}" DataTextField="name" DataTextFormatString="{0}" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="160px">
listFile.aspx.cs
string connstr="workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand("select * from blob", connection );
connection.Open();
SqlDataAdapter adaptor = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adaptor.Fill(ds,"blob");
connection.Close();
this.DataGrid1.DataSource=ds.Tables["blob"].DefaultView;
this.DataGrid1.DataBind();
getFile.aspx.cs//这个文件比较重要负责把村道数据库里面的文件,按照格式,按照名称,给传输出来
private void Page_Load(object sender, System.EventArgs e)
{
string imgid =this.Request.QueryString.Get("ID");
//Request.QueryString["imgid"];
string connstr="workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
string sql="SELECT name,blob, type FROM blob WHERE id = " + imgid;
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
Response.Clear();
Response.Buffer= true;
Response.
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>