首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

在線等,以次多選刪除報錯

2011-12-26 
在線等,,以下多選刪除報錯,將varchar數值GridView1.DataKeys[gvr.DataItemIndex].Value轉換成資料型別為in

在線等,,以下多選刪除報錯,
將   varchar   數值   'GridView1.DataKeys[gvr.DataItemIndex].Value '   轉換成資料型別為   int   的資料行語法錯誤。

protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                if   (!IsPostBack)
                {
                        string   connStr   =   ConfigurationManager.ConnectionStrings[ "BTS "].ConnectionString;
                        SqlConnection   conn   =   new   SqlConnection(connStr);
                        conn.Open();
                        DataSet   ds   =   new   DataSet();
                        SqlCommand   comm   =   new   SqlCommand();
                        SqlDataAdapter   sqlad   =   new   SqlDataAdapter();
                        comm.Connection   =   conn;
                        comm.CommandText   =   "select   *   from   bts ";
                        sqlad.SelectCommand   =   comm;
                        //Response.Write(sqlad.SelectCommand.CommandText);
                        sqlad.Fill(ds,   "bts ");
                        GridView1.DataSource   =   ds.Tables[ "bts "];
                        GridView1.DataBind();
                }
        }
protected   void   Button3_Click(object   sender,   EventArgs   e)
        {
                foreach   (GridViewRow   gvr   in   GridView1.Rows)
                {
                        CheckBox   ch   =   (CheckBox)gvr.FindControl( "ItemCheckBox ");
                        if   (ch.Checked)
                        {
                                //Ret2.Text   +=   " <li> GridView1   您选择的是(键值): "   +   GridView1.DataKeys[gvr.DataItemIndex].Value.ToString();
                                string   connStr   =   ConfigurationManager.ConnectionStrings[ "BTS "].ConnectionString;
                                SqlConnection   conn   =   new   SqlConnection(connStr);


                                conn.Open();
                                DataSet   ds   =   new   DataSet();
                                SqlCommand   comm   =   new   SqlCommand();
                                SqlDataAdapter   sqlad   =   new   SqlDataAdapter();
                                string   sql;
                                sql   =   "delete   from   bts   where   au_id=   'GridView1.DataKeys[gvr.DataItemIndex].Value ' ";
                                comm.Connection   =   conn;
                                comm.CommandText   =   sql;
                                comm.ExecuteNonQuery();

                        }
                }
        }

        protected   void   CheckAll(object   sender,   EventArgs   e)
        {
                CheckBox   cbx   =   (CheckBox)sender;
                foreach   (GridViewRow   gvr   in   GridView1.Rows)
                {
                        CheckBox   ch   =   (CheckBox)gvr.FindControl( "ItemCheckBox ");
                        ch.Checked   =   cbx.Checked;
                }
        }

[解决办法]
而且在你删除数据的时候,为啥还要定义:
DataSet ds = new DataSet();
SqlDataAdapter sqlad = new SqlDataAdapter();
?????
[解决办法]
sql = "delete from bts where au_id= ' " + GridView1.DataKeys[gvr.DataItemIndex].Value.ToString() + " ' ";

热点排行