开发者

Make SQL result have a class type

开发者 https://www.devze.com 2023-04-04 04:55 出处:网络
This is my first C# project, using VS 2008 and .NET 3.5, required by the client. I have a List of type GradeVO

This is my first C# project, using VS 2008 and .NET 3.5, required by the client.

I have a List of type GradeVO

This is my connection and where I'm setting values to a DataGridView

DataSet ds = new DataSet();
SqlConnection Conexao = new SqlConnection(@"Data Source=localhost; Initial Catalog=usr_mmidia; User ID=usr_mmidia; Password=123; MultipleActiveResultSets = true");
Conexao.Open();
SqlDataAdapter da = new SqlDataAdapter("MAG_SP_LISTA_SETORES_SQL", Conexao);
da.SelectCommand.Parameters.Add(new SqlParameter(("@p_codfil"), @"500"));
da.SelectCommand.Parameters.Add(new SqlParameter(("@p_categoria"), categoria));
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataTable t = new DataTable();
da.Fill(t);
dgNivel1.DataSource = t;

This code is working but I need the DataSource to receive a list of Gr开发者_运维知识库adeVO, is it possible?

Thanks in advance.


you could always do something like :

var myDataSource = t.Select(row => new GradeVO 
                                       {
                                           //your initialization logic here to get 
                                           //stuff from the row into the object
                                       });
dgNivel1.DataSource = myDataSource;
0

精彩评论

暂无评论...
验证码 换一张
取 消