注册 登录
编程论坛 ASP.NET技术论坛

GridView删除数据时出错,com.ExecuteNonQuery()运行不下去了

redpig 发布于 2007-06-14 17:15, 852 次点击
//Access
connectionStringg 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数据类型弄成相同的。
4 回复
#2
zsf20062007-06-14 17:31
GridView不是很熟悉,待高手指点。。。
不知道哪儿有具体的示例,可以学习学习
#3
川流不息2007-06-14 18:23
web_id你這個字段的類型是什麼?不是字符串吧?
#4
川流不息2007-06-14 18:24
如果是整型,單引號就不要加:
string sqlstr = "delete from tb_website where web_id=" + GridView1.DataKeys[e.RowIndex].Value.ToString() ;
#5
redpig2007-06-14 19:43
4楼正解,非常感谢
1