首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ExecuteNonQuery: CommandText 属性尚未初始化

2012-01-29 
紧急求助ExecuteNonQuery: CommandText 属性尚未初始化我的后台程序改了一下后,新增可以正常保存,但在现有

紧急求助ExecuteNonQuery: CommandText 属性尚未初始化
我的后台程序改了一下后,新增可以正常保存,但在现有的内容编辑后,就出现了“ExecuteNonQuery: CommandText 属性尚未初始化 ”

程序如下:
 if (Session["action"].ToString() == "edit")
  {
  try
  {//修改数据库

  string Edittext = new Common().GetText(txtContent.Text);
  SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConn"].ToString());
  SqlCommand comm = new SqlCommand("", conn);
  //"update Article set"
  // + "[News_first_title]='" + tbox_FirTitle.Text + "',"
  // + "[News_second_title]='" + tbox_SecTitle.Text + "',"
  // + "[News_third_title]='" + tbox_ThdTitle.Text + "',"
  // + "[News_time]='" + tbox_Date.Text + "',"
  // + "[News_author]='" + tbox_Author.Text + "',"
  // + "[News_content]='" + Edittext + "',"
  // + "[News_homepage_tag]='" + chk_HomePage.Checked + "',"
  // + "[News_photo_tag]='" + chk_Flash.Checked + "',"
  // + "[News_affiche_tag]='" + chk_Affiche.Checked + "',"
  // + "[News_top_tag]='" + chk_Top.Checked + "',"
  // + "[news_public_tag]='" + chk_Public.Checked + "',"
  // + "[news_hot_tag]='" + chk_Hot.Checked + "',"
  // + "[News_attachment]='" + str_Attachment + "',"
  // + "[news_public_type]='" + ddlist_PublicType.SelectedItem.Text + "',"
  // + "[news_affiche_time]='" + tbox_Affiche.Text + "',"
  // + "[news_group_mark]='" + Session["type"].ToString()
  // + "' WHERE [News_id]='" + Session["keys"] + "'"
  if (strID != null)
  {
  for (int ni = 0; ni < strID.Length; ni++)
  {
  sql += "insert into [Article] ("
  + "[News_first_title],"
  ...
  + "VALUES ('" + tbox_FirTitle.Text + "',"
  + "'" + tbox_SecTitle.Text + "',"
  ...
,"
  + "'" + strID[ni] + "'"
  + ");";
  }
  }
  sql = "delete from Article where News_id ='" + Session["keys"] + "';" + sql;
  conn.Open();
  comm.ExecuteNonQuery();
  conn.Close();
  comm.Dispose();
  conn.Dispose();
  }
  catch (Exception f)
  {
  Response.Write(f.Message.ToString());
  }
  }
  else
  {
  try
  {//存入数据库
  string Edittext = new Common().GetText(txtContent.Text);
  SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConn"].ToString());


  SqlCommand comm = new SqlCommand("",conn);
  if (strID != null)
  {
  for (int ni = 0; ni < strID.Length; ni++)
  {
  sql += "insert into [Article] ("
  + "[News_first_title],"
  ..."
  + "VALUES ('" + tbox_FirTitle.Text + "',"
  + "'" + tbox_SecTitle.Text + "',"
  ...
  + "'" + tbox_Affiche.Text + "',"
  + "'" + strID[ni] + "'"
  + ");";
  }

  }
  else
  {
   
  sql = "insert into [Article] ("
  + "[News_first_title],"
  ...
  + "[news_group_mark]) "
  + "VALUES ('" + tbox_FirTitle.Text + "',"
  + "'" + tbox_SecTitle.Text + "',"
  ...
  + "'" + Session["type"].ToString() + "'"
  + ");";
  }
  comm.CommandText = sql.Substring(0, sql.Length - 1);
  conn.Open();
  comm.ExecuteNonQuery();
  conn.Close();
  comm.Dispose();
  conn.Dispose();
  }
  catch (Exception f)
  { Response.Write(f.Message.ToString()); }
  }

  Session["typeID"] = null;
  Session["typeName"] = null;
  ds.Tables[0].Rows[0]["name"] = " ";
  ds.WriteXml(Server.MapPath("XML_UpFile.xml"));
  Server.Transfer("manager_content_list.aspx", true);
  }
  protected void btn_Return_Click(object sender, EventArgs e)
  {
  Server.Transfer("manager_content_list.aspx", true);
  }





}

[解决办法]
sql = "delete from Article where News_id ='" + Session["keys"] + "';" + sql;
comm.CommandText = sql;
conn.Open();
comm.ExecuteNonQuery();
[解决办法]

探讨

sql = "delete from Article where News_id ='" + Session["keys"] + "';" + sql;
comm.CommandText = sql;
conn.Open();
comm.ExecuteNonQuery();

[解决办法]
支持1楼的 你没有设置commandText 要嘛你再声明 command是制定 sqlcommand cmd=new sqlcommand(sql,conn);sql是commandtext conn是连接数据库字符 。 要嘛你就在声明command对象后在制定commandtext sqlcommand cmd=news qlcommand(); cmd。connection=conn;
cmd.commandtext=sql
------解决方案--------------------


探讨
sql = "delete from Article where News_id ='" + Session["keys"] + "';" + sql;
comm.CommandText = sql;
conn.Open();
comm.ExecuteNonQuery();

[解决办法]
sql = "delete from Article where News_id ='" + Session["keys"] + "';" + sql;
因为它

热点排行