| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 449 人关注过本帖
标题:数据不能更新
只看楼主 加入收藏
abao1234
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-8-26
收藏
 问题点数:0 回复次数:1 
数据不能更新
using System;
using System.Collections;
using
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using
using System.Data.SqlClient;

public partial class Admin_Admin_Edit : System.Web.UI.Page
{
    private Int32 FileLength = 0;
    OleDbConnection MyConn;
    protected void Page_Load(object sender, EventArgs e)
    {   
        MyConn=DB.CreateDB();
        MyConn.Open();
        if (Session["UserID"] == "" || Session["UserID"] == null)
        {
            Response.Write("<script language=javascript>window.alert('为了系统安全,请您重新登陆');window.location.href=('Admin_Login.aspx')</script>");
        }
        try
         {
            string id= Request.QueryString["id"].ToString();
            string ww="select * from product where id="+id+"";
            OleDbCommand Cm = new OleDbCommand(ww, MyConn);
            OleDbDataReader dr=Cm.ExecuteReader();
        
        if(dr.Read())
        {
             this.TxtTitle.Text=dr["title"].ToString();
             this.TxtContent.Text=dr["content"].ToString();
             this.label.Text=dr["img"].ToString();
        }
             }
         catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "')</script>");
            }
     }
    protected void BtnnSubmit_Click(object sender, EventArgs e)
    {    
        MyConn=DB.CreateDB();
        MyConn.Open();
        {
            try
            {
                string id= Request.QueryString["id"].ToString();
                string title =FunStr(this.TxtTitle.Text);
                string content =FunStr(this.TxtContent.Text);
                string FileName = myFile.Value;
                HttpPostedFile UpFile = myFile.PostedFile; //获取对由客户端指定的上传文件的访问
                FileLength = UpFile.ContentLength;//获取上传文件的字节大小
                if (FileLength == 0)
                {
                    OleDbCommand cmd1 = new OleDbCommand("update product set title="+title+",content="+content+" where id="+id+"",MyConn);
                    cmd1.ExecuteNonQuery();
                    Response.Write("<script>alert('数据更新成功')</script>");
                }
                else
                {
                    string exName = FileName.Substring(FileName.LastIndexOf(".") + 1).ToUpper();//截取图片的后缀名
                    if (exName == "JPG" || exName == "BMP" || exName == "GIF")//判断图片的类型
                    {
                        if (FileLength > 204800)//判断图片是否大于200k(根据自己的需要判断大小)
                        {
                            Response.Write("<script>alert('对不起,图片大小不能大于200K')</script>");
                            return;
                        }
                        else
                        {
                            string ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + "." + exName;//图片名称设置为保存的时间
                            Byte[] FileByte = new Byte[FileLength];
                            Stream ObjectStream = UpFile.InputStream;

                            ObjectStream.Read(FileByte, 0, FileLength); //读取图象文件数据
                            string StrSql = "update product set img="+ImageName+", title="+title+",content="+content+" where id="+id+"";
                            OleDbCommand Cmd = new OleDbCommand(StrSql, MyConn);
                            //Cmd.Parameters.Add("@Image",OleDbType.Binary, FileLength).Value = FileByte;
                            Cmd.Parameters.Add("@ImageName", OleDbType.VarChar, 100).Value = ImageName;
                            Cmd.ExecuteNonQuery();
                            Response.Write("<script>alert('数据更新成功')</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('对不起,请选择正确的的图片!')</script>");
                        return;
                    }
                    
                }
               
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "')</script>");
            }
        }

    }
    public static string FunStr(string str)
    {
        str = str.Replace("'", "‘");
        str = str.Replace("   ", "&nbsp;");

        str = str.Trim();
        if (str.Trim().ToString() == "")
            str = "无";
        return str;
    }

}
搜索更多相关主题的帖子: 数据 
2008-11-19 14:26
谁与争瘋
Rank: 2
等 级:论坛游民
帖 子:360
专家分:14
注 册:2008-11-18
收藏
得分:0 
不知道LZ调试的时候看传入的数据了没有?
2008-11-19 14:37
快速回复:数据不能更新
数据加载中...
 
   



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

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