找不到类型或命名空间名称“FileStream”(是否缺少 using 指令或程序集引用?)
using System;using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class up : System.Web.UI.Page
{
//SqlConnection con = new SqlConnection("server=.;database=photoDB;integrated security=sspi");
protected void Page_Load(object sender, EventArgs e)
{
}
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 conn = new SqlConnection("server=.;database=photoDB;integrated security=sspi");
SqlCommand cmd = conn.CreateCommand();
conn.Open();
cmd.CommandText = "insert into upphoto (Image_Content) values (@content)";
cmd.CommandType = CommandType.Text;
if (type == "jpg" || type == "gif" || type == "bmp" || type == "png")
{
SqlParameter para = cmd.Parameters.Add ("@content", SqlDbType.Image);
para.Value = content;
cmd.ExecuteNonQuery();
}
}
}
错误 1 找不到类型或命名空间名称“FileStream”(是否缺少 using 指令或程序集引用?) E:\photo111\photo1111\up.aspx.cs 30 7 E:\photo111\photo1111\
--------------------编程问答-------------------- 这是段上传代码 找不到类型或命名空间名称“FileStream”(是否缺少 using 指令或程序集引用?)
具体该怎么解决呢 --------------------编程问答-------------------- 添加IO引用即可,如下红色部分。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO; --------------------编程问答-------------------- using System.IO; --------------------编程问答--------------------
以后遇到这种情况自己搞。 --------------------编程问答-------------------- 嗯嗯 谢谢 另外这段代码好像上传功能没有实现啊 怎么办 上传之后数据库里没有显示 我用的是SQL2005
补充:.NET技术 , ASP.NET