求助一个录入问题~
public partial class admin_product : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int id = int.Parse(DropDownList1.SelectedValue);
DropDownList2.SelectedIndex = id;
}
protected void Button1_Click1(object sender, EventArgs e)
{
if (this.FileUpload1.HasFile)//检查是否有文件
{
string fullFileName = this.FileUpload1.PostedFile.FileName; //文件路径名
string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); //图片名称
string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1); //图片格式
if (type == "jpg" || type == "JPG" || type == "gif" || type == "GIF" || type == "BMP" || type == "bmp") //判断是否为图片类型
{
if (this.FileUpload1.PostedFile.ContentLength > 5000 * 1024)
{
Response.Write("<script>alert('上传图片必须小于500k!');</script>");
}
else
{
string path = HttpContext.Current.Request.MapPath("~/pic/");//获取上传文件的网站目录路径
this.FileUpload1.SaveAs(path + fileName);//存储文件到磁盘
Response.Write("<script>alert('图片上传成功!');</script>");//提示
this.Image1.ImageUrl = "~/pic/" + fileName;//显示图片
}
}
else
{
Response.Write("<script>alert('非图片类型,不允许上传!');</script>");
}
}
else
{
Response.Write("<script>alert('必须指定文件!');</script>");
}
string sqlConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(sqlConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into product(title,typeid,ntypeid,pic,note) values(@title,@typeid,@ntypeid,@pic,@note)";
string title = TextBox1.Text;
string typeid = "";
if(DropDownList1.SelectedItem != null)
{
typeid = DropDownList1.SelectedValue;
}
string ntypeid = "";
if (DropDownList2.SelectedItem != null)
{
ntypeid = DropDownList2.SelectedValue;
}
string note = txtTitle.Text;
string pic = "";
if(FileUpload1.PostedFile!=null)
{
pic=FileUpload1.PostedFile.FileName;
}
cmd.Parameters.Add(new SqlParameter("@pic", pic));
cmd.Parameters.Add(new SqlParameter("@title", title));
cmd.Parameters.Add(new SqlParameter("@typeid", typeid));
cmd.Parameters.Add(new SqlParameter("@note", note));
cmd.Parameters.Add(new SqlParameter("@ntypeid", ntypeid));
cmd.Connection = con;
con.Open();
SqlDataReader sdr = cmd.EndExecuteReader();
this.content.ContentPlaceHolder1 = sdr;
this.content.DataBind();
con.Close();
}
}
现在报错的是CS1501: “EndExecuteReader”方法没有采用“0”个参数的重载
我该怎么办?还有请高手说下 我现在的pic是否录入的是fileupload1的图片路径,还是应该写成
cmd.Parametera.Add(new SqlParameter("@pic",path + fileName)),如果这样写可以,那么前面又做什么修改呢,请高手赐教 --------------------编程问答-------------------- “EndExecuteReader”方法没有采用“0”个参数的重载
ps:看下这个方法是如何使用的 --------------------编程问答-------------------- 现在报错的是CS1501: “EndExecuteReader”方法没有采用“0”个参数的重载
这个错误 是不是说明需要参数啊,
cmd.EndExecuteReader(); 看看 cmd应该有其他方法执行 sqldataread赋值对象吧 --------------------编程问答-------------------- 已经修改SqlDataReader sdr = cmd.ExecuteReader();
新问题this.content.ContentPlaceHolder1 = sdr;
this.content.DataBind();
CS1061: “admin_product”不包含“content”的定义,并且找不到可接受类型为“admin_product”的第一个参数的扩展方法“content”(是否缺少 using 指令或程序集引用?)
我页面是在<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">容器内的
--------------------编程问答-------------------- protected void Button5_Click(object sender, EventArgs e)
{
bool fileIsValid = false;
//如果确认了上传文件,则判断文件类型是否符合要求
if (this.FileUpload1.HasFile)
{
//获取上传文件的后缀
String fileExtension = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower();
String[] restrictExtension = { ".gif", ".jpg", ".bmp", ".png" };
//判断文件类型是否符合要求
for (int i = 0; i < restrictExtension.Length; i++)
{
if (fileExtension == restrictExtension[i])
{
fileIsValid = true;
}
}
}
//如果文件类型符合要求,调用SaveAs方法实现上传,并显示相关信息
if (fileIsValid == true)
{
try
{
this.Image1.ImageUrl = "~/images/" + FileUpload1.FileName;
this.FileUpload1.SaveAs(Server.MapPath("~/images/") + FileUpload1.FileName);
this.Label3.Text = "文件上传成功";
this.Label3.Text += "<Br/>";
this.Label3.Text += "<li>" + "原文件路径:" + this.FileUpload1.PostedFile.FileName;
this.Label3.Text += "<Br/>";
this.Label3.Text += "<li>" + "文件大小:" + this.FileUpload1.PostedFile.ContentLength + "字节";
this.Label3.Text += "<Br/>";
this.Label3.Text += "<li>" + "文件类型:" + this.FileUpload1.PostedFile.ContentType;
}
catch
{
this.Label3.Text = "文件上传不成功!";
}
finally
{
}
}
else
{
this.Label3.Text ="只能够上传后缀为.gif,.jpg,.bmp,.png的文件夹";
}
}
运行的时候出现这个错误 CS1061: “上传图片”不包含“Image1”的定义,并且找不到可接受类型为“上传图片 是怎么回事 --------------------编程问答-------------------- EndExecuteReader
改为
ExecuteReader
补充:.NET技术 , ASP.NET