更新gridview操作错误发生帮助我 [英] Updating in gridview operation error occurs help me

查看:74
本文介绍了更新gridview操作错误发生帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据源是无效类型,必须是 IListSource IEnumerable IDataSource

Data source is an invalid type, it must be either an IListSource, IEnumerable or IDataSource.

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       
        string Sno = ((TextBox)GridView1.Rows[e.RowIndex]
                            .FindControl("txtSno")).Text;
        string Name = ((TextBox)GridView1.Rows[e.RowIndex]
                            .FindControl("txtName")).Text;
        string Age = ((TextBox)GridView1.Rows[e.RowIndex]
                            .FindControl("txtage")).Text;
        string Address = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtaddress")).Text;

        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "update Details set Sno=@Sno, Name=@Name," +
     "Age=@Age where Sno=@Sno;" +
     "select Sno,Name,Age,Address from Details";

        cmd.Parameters.Add("@Sno", SqlDbType.Int).Value = Sno;
        cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = Name;
        cmd.Parameters.Add("@Age", SqlDbType.VarChar).Value = Age;
        cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = Address;

        GridView1.EditIndex = -1;
        GridView1.DataSource = (cmd);
        GridView1.DataBind();



当我运行错误时,如下所示数据源是无效类型。它必须是 IListSource IEnumerable IDataSource

在此行中出现错误


When I run error occurs as follows Data source is an invalid type. It must be either an IListSource, IEnumerable or IDataSource.
In this line error occurs

GridView1.DataSource = (cmd);





请帮助我发送上面代码的问题是什么。



Please help me what is the problem form the above code I send.

推荐答案

你正在为Gridview数据源分配cmd这是错误的

GridView1.DataSource =(cmd);

您必须将datatbale分配给Gridview。

执行cmd并将数据导入datatable并分配给gridview
you are assigning "cmd" to Gridview Datasource which is wrong
GridView1.DataSource = (cmd);
You have to assign datatbale to Gridview.
execute cmd and get data into datatable and assign to gridview


你好......





你无法分配gridview.datasource =(cmd);



你可以分配数据集或数据表



GridView1 .DataSource = ds;





GridView1.DataSource = dt;







取决于你的填充方法
Hello ...


you can not assign gridview.datasource=(cmd);

you can assign dataset or datatable

GridView1.DataSource = ds;
or

GridView1.DataSource = dt;



depends on your fill method


你没有执行你的com在将cmd分配给网格之前执行cmd。

1)执行cmd并将其保存在数据表或数据集中。

2)将数据集/数据绑定到网格
You are not executing your command cmd before assigning it to grid.
1) execute cmd and save it in datatable or dataset.
2) Bind dataset/datatable to grid


这篇关于更新gridview操作错误发生帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆