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();
}
}
Mageshwaran RPosted Nov 24, 2019, 11:25 AM
Haidon DiogenesPosted Feb 10, 2016, 11:44 AM
DataTable dtPre1 = new DataTable("tperfil");
objsql1.Fill(dtPre1);
dgvPerfil.ItemsSource = dtPre1.DefaultView;
Haidon DiogenesPosted Feb 10, 2016, 10:56 AM
Shubham KumarPosted Feb 10, 2016, 7:54 AM