页面代码:<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();
}