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();
}
}

Shubham KumarRank #621 · 3.8K reputationPosted Feb 10, 2016, 2:54 AM EST
Haidon Diogenes20 reputationPosted Feb 10, 2016, 5:56 AM EST
Haidon Diogenes20 reputationPosted Feb 10, 2016, 6:44 AM EST
DataTable dtPre1 = new DataTable("tperfil");
objsql1.Fill(dtPre1);
dgvPerfil.ItemsSource = dtPre1.DefaultView;
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 24, 2019, 6:25 AM EST