K
Kylin
I write a page that delete the records from a dataset ,
and update to the data base ,
I click the delete button ,all that are right !
but when I refresh this page ,
a record will be deleted ! that's not I want .
why ?
and any ways about this
==============code under here !================
private SqlConnection myConn;
private SqlCommand myComm;
private SqlDataAdapter myAdapter;
private DataSet data=new DataSet() ;
private SqlCommandBuilder nameCmdBd ;
private void Page_Load(object sender, System.EventArgs e)
{
// ÔÚ´Ë´¦·ÅÖÃÓû§´úÂëÒÔ³õʼ»¯Ò³Ãæ
myConn=new SqlConnection("server=127.0.0.1;user
id=sa;pwd=sa;database=pubs");
myComm=new SqlCommand("Select a.* ,b.* From sales a , titles b Where
a.title_id=b.title_id",myConn);
myAdapter=new SqlDataAdapter();
myAdapter.SelectCommand=myComm;
myAdapter.Fill(data);
if(!this.IsPostBack)
{
DGBind();
}
}
private void BtnDelete_Click(object sender, System.EventArgs e)
{
for(int i=0;i<DataGrid1.Items.Count;i++)
{
CheckBox remove=(CheckBox)DataGrid1.Items.FindControl("remove");
if (remove.Checked==true)
{
// Response.Write(DataGrid1.DataKeys.ToString()+"</br>");
data.Tables[0].Rows.Delete();
}
}
myAdapter.SelectCommand.CommandText="Select * From sales";
nameCmdBd=new SqlCommandBuilder(myAdapter);
myAdapter.Update(data,"Table");
DGBind();
}
=========================code end ====================
Thanks a lot !
and update to the data base ,
I click the delete button ,all that are right !
but when I refresh this page ,
a record will be deleted ! that's not I want .
why ?
and any ways about this
==============code under here !================
private SqlConnection myConn;
private SqlCommand myComm;
private SqlDataAdapter myAdapter;
private DataSet data=new DataSet() ;
private SqlCommandBuilder nameCmdBd ;
private void Page_Load(object sender, System.EventArgs e)
{
// ÔÚ´Ë´¦·ÅÖÃÓû§´úÂëÒÔ³õʼ»¯Ò³Ãæ
myConn=new SqlConnection("server=127.0.0.1;user
id=sa;pwd=sa;database=pubs");
myComm=new SqlCommand("Select a.* ,b.* From sales a , titles b Where
a.title_id=b.title_id",myConn);
myAdapter=new SqlDataAdapter();
myAdapter.SelectCommand=myComm;
myAdapter.Fill(data);
if(!this.IsPostBack)
{
DGBind();
}
}
private void BtnDelete_Click(object sender, System.EventArgs e)
{
for(int i=0;i<DataGrid1.Items.Count;i++)
{
CheckBox remove=(CheckBox)DataGrid1.Items.FindControl("remove");
if (remove.Checked==true)
{
// Response.Write(DataGrid1.DataKeys.ToString()+"</br>");
data.Tables[0].Rows.Delete();
}
}
myAdapter.SelectCommand.CommandText="Select * From sales";
nameCmdBd=new SqlCommandBuilder(myAdapter);
myAdapter.Update(data,"Table");
DGBind();
}
=========================code end ====================
Thanks a lot !