问题描述
protectedvoidListBox1_Load(objectsender,EventArgse){strings=(string)Session["cDepCode"];stringsettings=Convert.ToString(ConfigurationManager.ConnectionStrings["Sdfey.Wssl"]);SqlConnectionmyconn=newSqlConnection(settings);stringmysql="selectid,cInvName+':'+cInvStdasds1fromcartwherecDepCode='"+s+"'";SqlCommandmycmd=newSqlCommand(mysql,myconn);DataSetds=newDataSet();myconn.Open();SqlDataAdaptermyadapter=newSqlDataAdapter(mysql,myconn);myadapter.Fill(ds,"cart");this.ListBox1.DataSource=ds;this.ListBox1.DataTextField="ds1";this.ListBox1.DataValueField="id";this.ListBox1.DataBind();==================================上述语句能正常读出数据================================================================下述语句无法正常作用==============================SqlConnectionmyconn1=newSqlConnection(settings);stringmysql1="selectidasds3fromcartwherecDepCode='"+s+"'";SqlCommandmycmd1=newSqlCommand(mysql1,myconn1);DataSetds2=newDataSet();myconn1.Open();SqlDataAdaptermyadapter1=newSqlDataAdapter(mysql1,myconn1);myadapter1.Fill(ds2,"cart");DataRowdeleteRow=ds2.Tables["cart"].Rows[""];deleteRow.Delete();ds2.Tables["cart"].Rows.RemoveAt(ds3);try{myDA.Update(ds2.Tables[0]);}catch(Exceptionex){this.Response.Write(ex.Message);}}
解决方案
解决方案二:
想要表达的效果是:页面载入,ListBox读取临时表cart中cDepcode=Session["cDepCode"]的记录记录读取后,删除临时表cart中cDepcode=Session["cDepCode"]的记录~不知道能否实现~
解决方案三:
标记
解决方案四:
更换了下面的语句,依然不行。。。SqlConnectionmyconn1=newSqlConnection(settings);myconn1.Open();stringmysql1="deletefromcartwherecDepCode='"+s+"'";SqlCommandmycmd1=newSqlCommand(mysql1,myconn1);//从数据库中删除指定记录mycmd1.ExecuteNonQuery();//从DataSet中删除指定记录信息DataSet.Tables["cart"].Rows[myBind.Position].Delete();DataSet.Tables["cart"].AcceptChanges();myconn1.Close();