protected void Button1_Click(object sender, EventArgs e)
{
///////////////////////////////////
string name = FileUpload1.PostedFile.FileName;
string type = name.Substring(name.LastIndexOf(".") + 1);
FileStream fs = File.OpenRead(name);
byte[] content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();
SqlConnection cn = new SqlConnection("Data Source=4-05\\SQLEXPRESS;Initial Catalog=News123;Integrated Security=True");
SqlCommand cm = new SqlCommand("insert into image(image) values(@image)", cn);
cn.Open();
if (type == "jpg" || type == "gif" || type == "bmp" || type == "png")
{
cm.Parameters.Add("@image", SqlDbType.Image);
cm.Parameters["@image"].Value = content;
cm.ExecuteNonQuery();
cn.Close();
}
Response.Write("保存成功");
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection cn= new SqlConnection("Data Source=4-05\\SQLEXPRESS;Initial Catalog=News123;Integrated Security=True");
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载
- 1
- 2
前往页