数据源是无效类型。它必须是ilistource,ienumerable或idatasource。 [英] Data source is an invalid type. It must be either an ilistsource, ienumerable, or idatasource.

查看:410
本文介绍了数据源是无效类型。它必须是ilistource,ienumerable或idatasource。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我尝试了大部分的事情,但是如果你们都可以提供帮助就没有得到完美的解决方案



我尝试了什么:



 int id = Convert.ToInt32(Session [UserID]); 
string connection = ConfigurationManager.AppSettings [Connection]。ToString();

使用(SqlConnection con = new SqlConnection(connection))
{
con.Open();
using(SqlCommand cmd = new SqlCommand(Score_Page,con))
{

cmd.Parameters.AddWithValue(@ ID,id);
DataTable cop = new DataTable();
SqlDataAdapter sad = new SqlDataAdapter(cmd);
cmd.CommandType = CommandType.StoredProcedure;
sad.Fill(警察);
int sco =(int)cop.Rows [0] [0];
int scr = percentage();
int sro =(int)((sco * 100)/ scr);
//int.TryParse(cop.Rows [0] [0] .ToString(),out sro);
con.Close();
GridView1.DataSource = sro;
GridView1.DataBind();

解决方案

 GridView1.DataSource = cop; 


在不知道你想要什么的情况下,GridView无法提供帮助。如果您只想让GridView显示单个值,请执行此操作



 GridView1.DataSource = new List< int> {sro}; 


Hello everyone, I am tried most of the thing but didn't got the perfect solution if you can all can help

What I have tried:

int id = Convert.ToInt32(Session["UserID"]);
        string connection = ConfigurationManager.AppSettings["Connection"].ToString();

        using (SqlConnection con = new SqlConnection(connection))
        {
            con.Open();
            using (SqlCommand cmd = new SqlCommand("Score_Page", con))
            {

                cmd.Parameters.AddWithValue("@ID", id);
                DataTable cop = new DataTable();
                SqlDataAdapter sad = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;
                sad.Fill(cop);
                int sco = (int)cop.Rows[0][0];
                int scr = percentage();
                int sro = (int)((sco * 100) / scr);
                //int.TryParse(cop.Rows[0][0].ToString(), out sro);
                con.Close();
                GridView1.DataSource = sro;
                GridView1.DataBind();

解决方案

GridView1.DataSource = cop;


Without knowing exactly what you want the GridView to show it's impossible to help. If you only want the GridView so show a single value do this

GridView1.DataSource = new List<int>{ sro };


这篇关于数据源是无效类型。它必须是ilistource,ienumerable或idatasource。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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