private void GridViewToBind()
{
OleDbConnection con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/web/mdb/data.mdb");
con.Open();
OleDbDataAdapter odr = new OleDbDataAdapter();
odr.SelectCommand = new OleDbCommand("select * from login", con);
DataSet ds = new DataSet();
odr.Fill(ds, "emp");
this.GridView1.DataKeyNames = "userID";
this.GridView1.DataSource = ds.Tables["emp"].DefaultView;
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string userID = this.GridView1.DataKeys[e.RowIndex].ToString();
OleDbConnection con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/web/mdb/data.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand("delete from login where userID='" + userID + "'", con);
cmd.ExecuteNonQuery();
this.GridViewToBind();
}
运行错误,提示说无法将类型“string”隐式转换为“string[]”,错误行为:
this.GridView1.DataKeyNames = "userID";
请问怎么写才对???