este codigo es del boton donde se llama al metodo consultar y donde se recibe al objeto dt de tipo DataTable para tomar sus valores y ponerlos en un datagridview:
Código:
private void butconsultar_Click(object sender, EventArgs e)
{
Usuario usr = new Usuario();
DataTable dt= new DataTable();
//SqlDataReader da=usr.Consultar(System.Convert.ToInt32(clave.Text.ToString()));
//da.Read();
dt = usr.Consultar(System.Convert.ToInt32(clave.Text.ToString()));
dataGridView1.Rows.Clear();
dataGridView1.Rows.Add(1);
for (int i = 1; i <= dt.Rows.Count+1; i++)
{
/*dataGridView1.Rows[i].Cells[0].Value = dt.Rows[i][0].ToString();
dataGridView1.Rows[i].Cells[1].Value = dt.Rows[i][1].ToString();
dataGridView1.Rows[i].Cells[2].Value = dt.Rows[i][2].ToString();
dataGridView1.Rows[i].Cells[3].Value = dt.RowTs[i][3].ToString();*/
//dataGridView1.Rows[0].Cells[0].Value = da[1].ToString();
dataGridView1.Rows[i].Cells[0].Value = dt.Rows[i][0].ToString();
dataGridView1.Rows[i].Cells[1].Value = dt.Rows[i][1].ToString();
dataGridView1.Rows[i].Cells[2].Value = dt.Rows[i][2].ToString();
dataGridView1.Rows[i].Cells[3].Value = dt.Rows[i][3].ToString();
}
}