event in First was how to connect to the access database and fill the database in a dataset then bind it with the datagridview. The second problem cost me much time which was using the rowdeletingdatagridview to complement the function of deleting a row. That's the code below.
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source= C:\\Documents and Settings\\Administrator\\桌面\\study temp\\dataset\\dataset\\testdb.mdb;";
string select = "SELECT * FROM customer";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(select, conn);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
DataSet ds = new DataSet();
adapter.Fill(ds);
int index = e.RowIndex;
ds.Tables[0].Rows[index].Delete();
adapter.Update(ds);
conn.Close();
}
Actually, those codes cannot reflect our design which hope to using four tiers structure to realize the functions. And one problem still need to be solved: how to bind the List

No comments:
Post a Comment