Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net SQL Server存储过程中的动态网格视图列_Asp.net_Sql Server - Fatal编程技术网

Asp.net SQL Server存储过程中的动态网格视图列

Asp.net SQL Server存储过程中的动态网格视图列,asp.net,sql-server,Asp.net,Sql Server,我的ASP.NET gridview列是否可能动态跟随从SQL Server存储过程返回的列?您可以分享一些技巧吗?您可以用来映射SQL Server存储过程(或任何其他SQL查询)中生成的列 首先,您需要创建一个学生类的列表(我这里以学生类为例),然后只需将其传递给GridView数据源即可 List<Student> students = getStudents(); gridview1.DataSource = students; 您有一个存储过程(或SQL查询),如 从

我的ASP.NET gridview列是否可能动态跟随从SQL Server存储过程返回的列?您可以分享一些技巧吗?

您可以用来映射SQL Server存储过程(或任何其他SQL查询)中生成的列

首先,您需要创建一个学生类的列表(我这里以学生类为例),然后只需将其传递给GridView数据源即可

List<Student> students = getStudents(); 
gridview1.DataSource = students; 
您有一个存储过程(或SQL查询),如 从学生姓名中选择ID

然后,您可以使用Dapper框架获得类似的内容

//If you using Query
List<Student> students = conn.Query<Student>("select ID,Name from Student", null, null, true, null, CommandType.Text).ToList(); 
//OR if you using stored procedure then
List<Student> students = conn.Query<Student>("StoredProcedureName", null, null, true, null, CommandType.StoredProcedure).ToList(); 
//如果使用查询
List students=conn.Query(“从学生中选择ID、名称”,null、null、true、null、CommandType.Text);
//或者,如果您使用存储过程
List students=conn.Query(“StoredProcedureName”,null,null,true,null,CommandType.StoredProcedure).ToList();

您尝过一些吗?无论如何,请使用AutoGenerateGolumns=true来实现这一点。
//If you using Query
List<Student> students = conn.Query<Student>("select ID,Name from Student", null, null, true, null, CommandType.Text).ToList(); 
//OR if you using stored procedure then
List<Student> students = conn.Query<Student>("StoredProcedureName", null, null, true, null, CommandType.StoredProcedure).ToList();