Have a good day.
I am populating a grid, and after searching the internet, I saw that some use the command:
cmd.CommandType = CommandType.Text;
My question is, why use? what's the difference? I did some testing here, and it works normally with or without this parameter.
Follow 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
{
}
}