标题:ASP.NET 在线图书销售系统,上架图书上传“时间”代码出错,望大神指正!! ...
取消只看楼主
麦尖浪花
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-12-16
结帖率:50%
已结贴  问题点数:20 回复次数:2 
ASP.NET 在线图书销售系统,上架图书上传“时间”代码出错,望大神指正!!!
public partial class admin_addproduvts : System.Web.UI.Page
{
    public string FileNamePic;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string filename = "pic" + System.DateTime.Now.ToString("YYYYMMDDHHmmssff");
        Boolean FileOK = false;
        string path = Server.MapPath("~/picture/");

        if (FileUpload1.HasFile)
        {
            string fileExtension = (FileUpload1.FileName).ToLower();
            string[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                if (fileExtension == allowedExtensions[i])
                { FileOK = true; break; }
            }
            if (FileOK)
            {
                try
                {

                    FileUpload1.PostedFile.SaveAs(path + filename + fileExtension);
                    Session["FileNamePic"] = filename + fileExtension;
                    Label1.Text = "文件上传成功!";
                }
                catch (Exception ex)
                { Label1.Text = "文件未上传!"; }
            }
        }
        else { Label1.Text = "文件不是图片类型"; }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
      
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ShoppingWebDBConnectionString"].ConnectionString);

        conn.Open();
        string sql = "insert into Products(Name,Picture)values(@Name,@Picture)";
        SqlCommand cmd1=new SqlCommand(sql,conn);
        
        cmd1.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar, 100));
        cmd1.Parameters["@Name"].Value = this.TextBox1.Text;
        cmd1.Parameters.Add(new SqlParameter("@ProductTypeID", SqlDbType.VarChar, 50));
        cmd1.Parameters["@ProductTypeID"].Value = this.TextBox2.Text;
        cmd1.Parameters.Add(new SqlParameter("@Author", SqlDbType.VarChar, 50));
        cmd1.Parameters["@Author"].Value = this.TextBox4.Text;
        cmd1.Parameters.Add(new SqlParameter("@PublicTime", SqlDbType.DateTime));
        cmd1.Parameters["PublicTime"].Value = System.DateTime.Now;
        cmd1.Parameters.Add(new SqlParameter("@InPrice", SqlDbType.Money, 50));
        cmd1.Parameters["InPrice"].Value = System.Convert.ToDouble(this.TextBox6.Text);
        cmd1.Parameters.Add(new SqlParameter("@OutPrice", SqlDbType.Money, 50));
        cmd1.Parameters["OutPrice"].Value = System.Convert.ToDouble(this.TextBox7.Text);
        cmd1.Parameters.Add(new SqlParameter("@Picture",SqlDbType.VarChar,50));
        cmd1.Parameters["@Picture"].Value=Session["FileNamePic"].ToString();
        cmd1.ExecuteNonQuery();
        conn.Close();
        Page.Controls.Clear();
        Response.Write(TextBox1.Text+"添加成功!");
    }
}

出现如下错误,望大神指正!
搜索更多相关主题的帖子: 在线图书 public false 
2014-11-29 02:02
麦尖浪花
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-12-16
得分:0 
回复 2 楼 hu9jj
哦,谢谢楼主哦
2014-11-29 10:49
麦尖浪花
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-12-16
得分:0 

原来是缺@了,问题终于解决了,功夫不负有心人那
2014-11-29 12:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-439324-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.128725 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved