using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1tiraduvidas
{
public partial class ClasseComLista : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Teste_Load(null, null);
}
public string myConnString
{
get
{
return "Server=.\\SQLEXPRESS;Database=BancoModelo;User ID=sa;Password=....";ID=sa;Password=814485";
}
}
private void Teste_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = myConnString;
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select NomeP.NomePapel , P.DtInclusao from tb_Juridico P ";
SqlDataAdapter sqla = new SqlDataAdapter();
DataTable Result = new DataTable();
sqla.SelectCommand = cmd;
conn.Open();
sqla.Fill(Result);
List<Juridic> od = new List<Juridic>();
var qrIn = from row in Result.AsEnumerable()
select new Juridic
{
Nome = row[0].ToString(),
DtInclusao = Convert.ToDateTime(row[1]),
};
var Lista = qrIn.ToList();
VerificaJuridico vj = new VerificaJuridico();
vj.ChecaJuridico(Lista);
}
finally
{
conn.Close();
}
}
}
public class VerificaJuridico
{
public void ChecaJuridico<T>(List<T> lista)
{
// se for uma lista generica (ChecaJuridico<T>(List<T>) vc vai ter que acessa os valores atraves da propriedade
var properties = typeof(T).GetProperties();
foreach (var item in lista)
{
foreach (var property in properties)
{
var name = property.Name;
var value = property.GetValue(item, null);
}
}
}
// ou assim vc pode fazer assim
public void ChecaJuridico(List<Juridic> lista)
{
foreach (var t in lista)
{
var nome = t.Nome;
var DtInclusao = t.DtInclusao;
}
}
}
public class Juridic
{
public string Nome { get; set; }
public DateTime DtInclusao { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1tiraduvidas
{
public partial class ClasseComLista : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Teste_Load(null, null);
}
public string myConnString
{
get
{
return "Server=.\\SQLEXPRESS;Database=BancoModelo;User ID=sa;Password=....";
}
}
private void Teste_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = myConnString;
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select Nome , DtInclusao from tb_Juridico ";
SqlDataAdapter sqla = new SqlDataAdapter();
DataTable Result = new DataTable();
sqla.SelectCommand = cmd;
conn.Open();
sqla.Fill(Result);
var qrIn = from row in Result.AsEnumerable()
select new Juridic
{
Nome = row[0].ToString(),
DtInclusao = Convert.ToDateTime(row[1]),
};
var Lista = qrIn.ToList();
VerificaJuridico vj = new VerificaJuridico();
vj.ChecaJuridico(Lista);
}
finally
{
conn.Close();
}
}
}
public class VerificaJuridico
{
public void ChecaJuridico(List<Juridic> lista)
{
foreach (var t in lista)
{
var nome = t.Nome;
var DtInclusao = t.DtInclusao;
}
}
}
public class Juridic
{
public string Nome { get; set; }
public DateTime DtInclusao { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1tiraduvidas
{
public partial class ClasseComLista : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Teste_Load(null, null);
}
public string myConnString
{
get
{
return "Server=.\\SQLEXPRESS;Database=BancoModelo;User ID=sa;Password=814485";
}
}
private void Teste_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = myConnString;
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select P.NomePapel , P.DtInclusao from tb_Juridico P ";
SqlDataAdapter sqla = new SqlDataAdapter();
DataTable Result = new DataTable();
sqla.SelectCommand = cmd;
conn.Open();
sqla.Fill(Result);
List<Juridic> od = new List<Juridic>();
var qrIn = from row in Result.AsEnumerable()
select new Juridic
{
Nome = row[0].ToString(),
DtInclusao = Convert.ToDateTime(row[1]),
};
var Lista = qrIn.ToList();
VerificaJuridico vj = new VerificaJuridico();
vj.ChecaJuridico(Lista);
}
finally
{
conn.Close();
}
}
}
public class VerificaJuridico
{
public void ChecaJuridico<T>(List<T> lista)
{
// se for uma lista generica (ChecaJuridico<T>(List<T>) vc vai ter que acessa os valores atraves da propriedade
var properties = typeof(T).GetProperties();
foreach (var item in lista)
{
foreach (var property in properties)
{
var name = property.Name;
var value = property.GetValue(item, null);
}
}
}
// ou assim vc pode fazer assim
public void ChecaJuridico(List<Juridic> lista)
{
foreach (var t in lista)
{
var nome = t.Nome;
var DtInclusao = t.DtInclusao;
}
}
}
public class Juridic
{
public string Nome { get; set; }
public DateTime DtInclusao { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1tiraduvidas
{
public partial class ClasseComLista : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Teste_Load(null, null);
}
public string myConnString
{
get
{
return "Server=.\\SQLEXPRESS;Database=BancoModelo;User ID=sa;Password=....";
}
}
private void Teste_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = myConnString;
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select Nome , DtInclusao from tb_Juridico ";
SqlDataAdapter sqla = new SqlDataAdapter();
DataTable Result = new DataTable();
sqla.SelectCommand = cmd;
conn.Open();
sqla.Fill(Result);
var qrIn = from row in Result.AsEnumerable()
select new Juridic
{
Nome = row[0].ToString(),
DtInclusao = Convert.ToDateTime(row[1]),
};
var Lista = qrIn.ToList();
VerificaJuridico vj = new VerificaJuridico();
vj.ChecaJuridico(Lista);
}
finally
{
conn.Close();
}
}
}
public class VerificaJuridico
{
public void ChecaJuridico<T>ChecaJuridico(List<T>List<Juridic> lista)
{
foreach (var t in lista)
{
var //..nome = t.Nome;
seu tratamento var DtInclusao = t.DtInclusao;
}
}
}
public class Juridic
{
public string Nome { get; set; }
public DateTime DtInclusao { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1tiraduvidas
{
public partial class ClasseComLista : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Teste_Load(null, null);
}
public string myConnString
{
get
{
return "Server=.\\SQLEXPRESS;Database=BancoModelo;User ID=sa;Password=....";
}
}
private void Teste_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = myConnString;
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select Nome , DtInclusao from tb_Juridico ";
SqlDataAdapter sqla = new SqlDataAdapter();
DataTable Result = new DataTable();
sqla.SelectCommand = cmd;
conn.Open();
sqla.Fill(Result);
var qrIn = from row in Result.AsEnumerable()
select new Juridic
{
Nome = row[0].ToString(),
DtInclusao = Convert.ToDateTime(row[1]),
};
var Lista = qrIn.ToList();
VerificaJuridico vj = new VerificaJuridico();
vj.ChecaJuridico(Lista);
}
finally
{
conn.Close();
}
}
}
public class VerificaJuridico
{
public void ChecaJuridico<T>(List<T> lista)
{
foreach (var t in lista)
{
//... seu tratamento
}
}
}
public class Juridic
{
public string Nome { get; set; }
public DateTime DtInclusao { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1tiraduvidas
{
public partial class ClasseComLista : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Teste_Load(null, null);
}
public string myConnString
{
get
{
return "Server=.\\SQLEXPRESS;Database=BancoModelo;User ID=sa;Password=....";
}
}
private void Teste_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = myConnString;
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select Nome , DtInclusao from tb_Juridico ";
SqlDataAdapter sqla = new SqlDataAdapter();
DataTable Result = new DataTable();
sqla.SelectCommand = cmd;
conn.Open();
sqla.Fill(Result);
var qrIn = from row in Result.AsEnumerable()
select new Juridic
{
Nome = row[0].ToString(),
DtInclusao = Convert.ToDateTime(row[1]),
};
var Lista = qrIn.ToList();
VerificaJuridico vj = new VerificaJuridico();
vj.ChecaJuridico(Lista);
}
finally
{
conn.Close();
}
}
}
public class VerificaJuridico
{
public void ChecaJuridico(List<Juridic> lista)
{
foreach (var t in lista)
{
var nome = t.Nome;
var DtInclusao = t.DtInclusao;
}
}
}
public class Juridic
{
public string Nome { get; set; }
public DateTime DtInclusao { get; set; }
}
}
Não sei como vc esta carregando o seu DataTable result
, mas vou dar um exemplo usando o banco de dados sql server para isso.
Veja abaixo..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1tiraduvidas
{
public partial class ClasseComLista : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Teste_Load(null, null);
}
public string myConnString
{
get
{
return "Server=.\\SQLEXPRESS;Database=BancoModelo;User ID=sa;Password=....";
}
}
private void Teste_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = myConnString;
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select Nome , DtInclusao from tb_Juridico ";
SqlDataAdapter sqla = new SqlDataAdapter();
DataTable Result = new DataTable();
sqla.SelectCommand = cmd;
conn.Open();
sqla.Fill(Result);
var qrIn = from row in Result.AsEnumerable()
select new Juridic
{
Nome = row[0].ToString(),
DtInclusao = Convert.ToDateTime(row[1]),
};
var Lista = qrIn.ToList();
VerificaJuridico vj = new VerificaJuridico();
vj.ChecaJuridico(Lista);
}
finally
{
conn.Close();
}
}
}
public class VerificaJuridico
{
public void ChecaJuridico<T>(List<T> lista)
{
foreach (var t in lista)
{
//... seu tratamento
}
}
}
public class Juridic
{
public string Nome { get; set; }
public DateTime DtInclusao { get; set; }
}
}
lang-cs