C#添加信息方法

    protected void btn_OK_Click(object sender, EventArgs e)
    {
        string name = "";
        if (FileUpload1.HasFile)
        {
            try
            {
                string ex_filename = System.IO.Path.GetExtension(FileUpload1.FileName).ToString().ToLower();
                name = DateTime.Now.ToString("yyyyMMddHHmmss") + ex_filename;
                if (ex_filename == ".jpg" || ex_filename == ".bmp" || ex_filename == ".png" || ex_filename == ".gif")
                {
                    FileUpload1.SaveAs(Server.MapPath("~/images/products/") + "\\" + name);
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('这不是图像文件!')</script>");
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }


        }
        else
        {
            Response.Write("<script language='javascript'>alert('请选选择要上传的文件!')</script>");
        }
        button(name);
    }


    protected void button(string name)
    {
        string str = "insert into products (pname,guige,weight,intro,photo,pubdate,price) values('" + txt_name.Text + "','" + txt_guige.Text + "','" + txt_weight.Text + "','" + txt_je.Text + "','" + name + "','" + DateTime.Now + "','" + txt_price.Text + "')";
       int result = 0;
       
       SqlConnection mycon = new SqlConnection();
       mycon.ConnectionString = ConfigurationManager.ConnectionStrings["sweetConnectionString"].ToString();
       SqlCommand mycom = new SqlCommand(str, mycon);
       try
       {
           mycon.Open();
           result = mycom.ExecuteNonQuery();
       }
       catch (Exception ex)
       {
           throw (ex);
       }
       finally
       {
           mycon.Close();
       }
       if (result != 0)
       {
           Response.Write("<script language='javascript'>alert('发布成功!')</script>");


       }
       else
           Response.Write("<script language='javascript'>alert('发布失败!')</script>");
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值