1
Good morning guys.
I’m populating a grid, and after searching the internet, I saw that some use the command:
cmd.CommandType = CommandType.Text;
My doubt, is, why use? what’s the difference? I did some tests here, and it works normally with or without this parameter.
Follows my code:
private void Form1_Load(object sender, EventArgs e)
{
string sqlstring, _sql;
int id_cliente = 3;
sqlstring = @"Server=tcp:tpspoazsql01.database.windows.net,1433;Data Source=tpspoazsql01.database.windows.net;Initial Catalog=Onee;Persist Security Info=False;User ID=********;Password=*********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
_sql = string.Empty;
SqlConnection sqlconn = new SqlConnection(sqlstring);
try
{
_sql = @"SELECT nome,endereco,numero,bairro,cidade,estado,cep FROM Cliente_enderecos_alter WHERE id_cliente = @id_cliente AND tipo = 'Cobrança'";
SqlCommand cmd = new SqlCommand(_sql, sqlconn);
cmd.Parameters.Add("@id_cliente", SqlDbType.Int).Value = id_cliente;
sqlconn.Open();
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable clientes = new DataTable();
da.Fill(clientes);
dataGridView1.DataSource = clientes;
}
catch
{
}
}
Good morning friend. Got it. Thanks for the explanation.
– Thomas Erich Pimentel
Always a pleasure to help, young man.
– Jéf Bueno