4
In terms of performance, speed, or even safety, what is the best object to be used as a DataSource
?
Example, I’m creating a DataSource
, to popular a GridView
:
For SqlDataSource
:
this.sqlDataSource1.ConnectionName = "sql brayton max";
this.sqlDataSource1.Name = "sqlDataSource1";
columnExpression7.ColumnName = "id";
table3.MetaSerializable = "0|0|125|100";
table3.Name = "NotaFiscal.Cidades";
columnExpression7.Table = table3;
column7.Expression = columnExpression7;
columnExpression8.ColumnName = "cd_uf";
columnExpression8.Table = table3;
column8.Expression = columnExpression8;
columnExpression9.ColumnName = "ds_cidade";
columnExpression9.Table = table3;
column9.Expression = columnExpression9;
selectQuery3.Columns.Add(column7);
selectQuery3.Columns.Add(column8);
selectQuery3.Columns.Add(column9);
selectQuery3.Name = "NotaFiscal_Cidades";
selectQuery3.Tables.Add(table3);
this.sqlDataSource1.Queries.AddRange(new DevExpress.DataAccess.Sql.SqlQuery[] {
selectQuery3});
this.sqlDataSource1.ResultSchemaSerializable = resources.GetString("sqlDataSource1.ResultSchemaSerializable");
By Datatable:
DataTable cli = new DataTable();
string sqconn, _sql;
sqconn = ConfigurationManager.ConnectionStrings["sql brayton max"].ConnectionString;
_sql = @"SELECT id,cd_uf,ds_cidade FROM NotaFiscal.Cidades";
SqlConnection con = new SqlConnection(sqconn);
try
{
SqlCommand cmd = new SqlCommand(_sql, con);
con.Open();
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(cli);
}
catch
{
}
Just for your information: Datatable: The Hidden Enemy;
– Thiago Lunardi