GridView删除数据时出错,com.ExecuteNonQuery()运行不下去了
//AccessconnectionStringg acccon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\corner\App_Data\db_corner.mdb;";
OleDbConnection con;
OleDbCommand com;
public void bind()//绑定
{
string sqlstr = "select * from tb_website";//表-网站
con = new OleDbConnection(connectionString);
OleDbDataAdapter da = new OleDbDataAdapter(sqlstr, con);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds, "tb_website"); //表-网站
GridView1.DataSource = ds;
GridView1.DataKeyNames=new string[] {"web_id"};//主键
GridView1.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')");
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from tb_website where web_id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
con = new OleDbConnection(connectionString);
com = new OleDbCommand(sqlstr, con);
con.Open();
com.ExecuteNonQuery();// 运行出错 ?标准表达式中数据类型不匹配。
con.Close();
bind();
}
添加监视
com.ExecuteNonQuery() int
GridView1.DataKeys[e.RowIndex].Value.ToString() string
不知道怎么改错了。求大虾指点,怎么样才能把2数据类型弄成相同的。