asp.net中怎样使修改后的内容进入数据库 各位大侠,是否明白小弟所说的意思,小弟项目当中遇到一个很奇怪的问题,在信息修改过程中,页面已经显示修改但数据库却没有更新是怎么回事呢,大家帮个忙多多指教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要学会调试在你修改的代码上下断点,看看有没有运行到这里,执行的SQL是否正确。 嗯嗯前辈说的对,可是报错时候好像是说数据库哪里有问题没有连接,可是我检查了web.config里的连接没什么问题,前辈你觉得呢?? 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; //} } }我认为好像是这里有问题,因为这里是两个外键,用下拉菜单显示的,前辈帮忙看看,我是菜鸟多多指教非常感谢 如果从函数名称上看,Get是读,Set是写。这两个函数会修改数据库么?你提到的报错是什么。 //更改酒店信息 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; } } SQL 语句有问题。找一本SQL手册看看UPDATE怎么写。 company.Type.Id应该值为null,你看看拿什么传给了company.Type.Id DIV + InnerHtml问题 一个困扰了我很久的看似简单的问题(关于DIV和TABLE) 把2页面合并在一个页面中 这种菜单效果怎么做呢? 求助,传值问题 请教关于TreeView的一些问题? 请求AJAX资料 .NET中使用OracleHelper的几个例子. 菜鸟请教 如何显示.SWF文件? 关于百度地图API覆盖物的问题 CalendarExtender 日历扩展器和AutoComplete自动完成扩展器 在iframe中位置偏移 错位,不在textbox的下方 如何获取动态生成的div的Id(急)
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; //}
}
}
我认为好像是这里有问题,因为这里是两个外键,用下拉菜单显示的,前辈帮忙看看,我是菜鸟多多指教非常感谢
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;
} }