页面代码:<INPUT language="C#" id="File1" style="Z-INDEX: 101; LEFT: 25px; POSITION: absolute; TOP: 24px" type="file" name="File1" runat="server">
<asp:button id="Button1" style="Z-INDEX: 102; LEFT: 282px; POSITION: absolute; TOP: 23px" runat="server" Text="UpLoad"></asp:button><asp:label id="Label1" style="Z-INDEX: 103; LEFT: 385px; POSITION: absolute; TOP: 24px" runat="server" Height="29px" Width="277px">Label</asp:label>上传图片代码:
private void Button1_Click(object sender, System.EventArgs e)
{
int length=File1.PostedFile.ContentLength;
byte[] buff=new Byte[length];
File1.PostedFile.InputStream.Read(buff,0,length);
SqlConnection conn=new SqlConnection("server=localhost;user id=sa;password=;database=db");
SqlParameter pm=new SqlParameter("@img",SqlDbType.Image);
pm.Value=buff;
SqlCommand cmd=new SqlCommand("insert images values(1,@img)",conn);
cmd.Parameters.Add(pm);
conn.Open();
Label1.Text=cmd.ExecuteNonQuery().ToString();
conn.Close();
}
<asp:button id="Button1" style="Z-INDEX: 102; LEFT: 282px; POSITION: absolute; TOP: 23px" runat="server" Text="UpLoad"></asp:button><asp:label id="Label1" style="Z-INDEX: 103; LEFT: 385px; POSITION: absolute; TOP: 24px" runat="server" Height="29px" Width="277px">Label</asp:label>上传图片代码:
private void Button1_Click(object sender, System.EventArgs e)
{
int length=File1.PostedFile.ContentLength;
byte[] buff=new Byte[length];
File1.PostedFile.InputStream.Read(buff,0,length);
SqlConnection conn=new SqlConnection("server=localhost;user id=sa;password=;database=db");
SqlParameter pm=new SqlParameter("@img",SqlDbType.Image);
pm.Value=buff;
SqlCommand cmd=new SqlCommand("insert images values(1,@img)",conn);
cmd.Parameters.Add(pm);
conn.Open();
Label1.Text=cmd.ExecuteNonQuery().ToString();
conn.Close();
}
解决方案 »
- 一个奇怪的winform问题(初始化窗体位置)
- Session赋值给类的时候提示:未将对象引用设置到对象的实例
- 请教一个设置评论的流程问题(防止重复提交)
- 问个简单的问题,minHeight对于IE6.0怎么没有效果的
- TreeView中使用checkbox,如何点击TreeView中的值,点checkbox自动打勾
- 安了微软的ajax1.0以后,客户端有那些脚本的智能感知吗?
- 在asp.net网页中怎样读出一个Excel文档?
- 如何获得类名,在线等待
- FreeTextBox文本编辑控件问题
- 有个问题,急,在线等?
- asp.net怎样与css结合啊?
- 请问怎样取得Datagrid中模板列中的控件的值??
HtmlInputFile 类 [C#]
原理见
http://www.aspcn.com/News/Show.aspx?id=256