This is a migrated thread and some comments may be shown as answers.

SQL data as to bring radgridview?...sorry I do not speak English

1 Answer 19 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
jorge
Top achievements
Rank 1
jorge asked on 29 Apr 2015, 05:30 PM

I make a query to a database SQL attempt to bring the result to a radGridView .... I add the row but no data as it should?

private void radButton1_Click(object sender, EventArgs e)
{
if(txtNro.Text=="")
MessageBox.Show("DEBE INGRESAR UN NRO DE ORDEN", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else
if (txtNro.Text != "")
{
conexion.Open();
SqlCommand consulta = new SqlCommand("select Convert(varchar(10),fecIni,103) as fecIni ,Convert(Varchar(10),fecFin,103) as fecFin from ordenes where nro_orden=@nro", conexion);
consulta.Parameters.AddWithValue("@nro", Convert.ToInt32(txtNro.Text));
SqlDataReader registro = consulta.ExecuteReader();
if (registro.Read())
{
labelIni.Text = Convert.ToString(registro["fecIni"]);
labelFinal.Text = Convert.ToString(registro["fecFin"]);
}
else
{
MessageBox.Show("NO SE ENCONTRO EL NUMERO DE ORDEN INGRESADO", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
labelIni.Text = "";
labelFinal.Text = "";
}
conexion.Close();
DataTable dt = new DataTable();
conexion.Open();
SqlCommand consulta2 = new SqlCommand("select medicamento,cantidad,programa,precioUnit,precioFin from DetalleOrden where nro_orden=@nro",conexion);
consulta2.Parameters.AddWithValue("@nro", Convert.ToInt32(txtNro.Text));
SqlDataAdapter da = new SqlDataAdapter(consulta2);
da.Fill(dt);
rgv.DataSource = dt;
conexion.Close();


}
}

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 May 2015, 08:12 AM
Hello Jorge,

Thank you for writing.

Our Databinding RadGridView help article is quite useful regarding populating the grid with data. You just need to fill a DataTable and set it as RadGridView.DataSource. On the following links you can find helpful information about how to create a DataTable from a query:

Please find attached a sample project as well.

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Dess
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
jorge
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or