一个datalist绑定到一个accessdatasource,如何在datalist控件上操作就可以删除数据库里面对应的数据?

解决方案 »

  1.   

    一个DataAdapter的事例,你要做些修改DataSet ds = null;
    SqlDataAdapter adapter = null;
    SqlCommandBuilder sqlbuilder = null;//该按钮读取数据,并绑定数据
    private void button1_Click(object sender, EventArgs e)
            ...{
                ds = new DataSet();
                SqlConnection cn = new SqlConnection("Data Source=.;User ID=sa;Password=sa;Initial Catalog=dbName");
                SqlCommand cm = new SqlCommand();
                adapter = new SqlDataAdapter(cm);
                sqlbuilder = new SqlCommandBuilder(adapter);
                cm.Connection = cn;
                cm.CommandType = CommandType.Text;
                cm.CommandText = "select * from [providerInfo]";
                adapter.Fill(ds);          //该方法把得到的数据放入一个DataTable中
                dataGridView1.DataSource = ds.Tables[0];    把数据绑定到DataGridView
            }//向数据库返回修改的数据.
    private void button2_Click(object sender, EventArgs e)
            ...{
                adapter.Update(ds); 
            }