各位大侠,是否明白小弟所说的意思,小弟项目当中遇到一个很奇怪的问题,在信息修改过程中,页面已经显示修改但数据库却没有更新是怎么回事呢,大家帮个忙多多指教

解决方案 »

  1.   

    要学会调试在你修改的代码上下断点,看看有没有运行到这里,执行的SQL是否正确。
      

  2.   

    嗯嗯前辈说的对,可是报错时候好像是说数据库哪里有问题没有连接,可是我检查了web.config里的连接没什么问题,前辈你觉得呢??
      

  3.   


            if (!IsPostBack)
            {
                BiandLoadStar();
                BiandLoadCpy();            //if (Request.QueryString["id"] != null)
                //{                Company cu = HotelBLL.CompanyManager.GetCompanyById(3);//Convert.ToInt32(Request.QueryString["id"]));
                    this.TextBox1.Text = cu.Name;
                    this.TextBox4.Text = cu.Address;
                    this.TextBox5.Text = cu.Contact;
                    this.TextBox6.Text = cu.Tel;
                    this.TextBox7.Text = cu.Email;
                    this.TextBox8.Text = cu.Url;
                    this.TextBox2.Text = cu.Note;
                    this.TextBox3.Text = cu.Enviroment;
                    if (cu.Process == true)
                    { 
                        this.RadioButtonList1.DataValueField = "0";
                    }
                    else { 
                        this.RadioButtonList1.DataValueField = "1"; 
                    }
                    if (cu.Actived == true)
                    {
                        this.RadioButtonList2.DataValueField = "0";
                    }
                    else {
                        this.RadioButtonList2.DataValueField = "1";
                    }
                    Companies_category cpry = Companies_categoryManager.GetCompanies_categoryById(Convert.ToInt32(this.DropDownList1.SelectedIndex));
                    cpry = cu.Type;
                    Starlevel star = StarlevelManager.GetStarlevelById(Convert.ToInt32(this.DropDownList2.SelectedIndex));
                    star = cu.StarLevel;
                //}
            }
        }
    我认为好像是这里有问题,因为这里是两个外键,用下拉菜单显示的,前辈帮忙看看,我是菜鸟多多指教非常感谢
      

  4.   

    如果从函数名称上看,Get是读,Set是写。这两个函数会修改数据库么?你提到的报错是什么。
      

  5.   

    //更改酒店信息
            public static int ModifyCompany(Company company)
            {
                string sql =
                    "UPDATE companies " +
                    "SET " +
                    "type = @type, " + //FK
                    "starLevel = @starLevel, " + //FK
                    "name = @name, " +
                    "address = @address, " +
                    "contact = @contact, " +
                    "tel = @tel, " +
                    "email = @email, " +
                    "url = @url, " +
                    "enviroment = @enviroment, " +
                    "note = @note, " +
                    "actived = @actived, " +
                    "process = @process " +
                    "WHERE id = @id";
                try
                {
    SqlParameter[] para = new SqlParameter[]
    {
    new SqlParameter("@id", company.Id),
    new SqlParameter("@type", company.Type.Id), //FK
    new SqlParameter("@starLevel", company.StarLevel.Id), //FK
    new SqlParameter("@name", company.Name),
    new SqlParameter("@address", company.Address),
    new SqlParameter("@contact", company.Contact),
    new SqlParameter("@tel", company.Tel),
    new SqlParameter("@email", company.Email),
    new SqlParameter("@url", company.Url),
    new SqlParameter("@enviroment", company.Enviroment),
    new SqlParameter("@note", company.Note),
    new SqlParameter("@actived", company.Actived),
    new SqlParameter("@process", company.Process)
    };      DBHelper.ExecuteCommand(sql, para);
                SqlCommand cmd = new SqlCommand(sql, DBHelper.Connection);
                int c = (int)cmd.ExecuteNonQuery();
               
                return c;            }
                catch (Exception e)??这里报错提示必须声明标量变量 "@type"。
                {
                    Console.WriteLine(e.Message);
    throw e;
                }        }
      

  6.   

    SQL 语句有问题。找一本SQL手册看看UPDATE怎么写。
      

  7.   

    company.Type.Id应该值为null,你看看拿什么传给了company.Type.Id