Hello , I want to make a DataGridView with the server data. It does not work and I think that is when >>> dgvPerfil.DataContext = dtPre1 ; <<< Below is the code in the method, the DataGridView is called dgvPerfil , and he will receive the connection string when the method is called . What am I missing ? Thank you all for your help.
public void ListPerfil(String verrdgda)
{
ConectionClass coneli = new ConectionClass();
cone.connect();
SqlCommand cverrdgda = new SqlCommand(verrdgda, cone.con);
try
{
SqlDataAdapter objsql1 = new SqlDataAdapter(cverrdgda);
DataTable dtPre1 = new DataTable();
objsql1.Fill(dtPre1);
dgvPerfil.DataContext = dtPre1;
}
catch
{
MessageBox.Show("Connecting to the server unavailable!", "Error");
cone.disconnect();
}
finally
{
coneli.desconectar();
}
}