ASp.net

Tuesday, September 8, 2015

how to show data in datagridview in c#

1 comment:

  1. private void Form1_Load(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=I:\C3 soft\WindowsFormsApplication2\WindowsFormsApplication2\MTechSqlDatabase.mdf;Integrated Security=True;Connect Timeout=30");
    SqlCommand cmd = new SqlCommand("Select * From UnitType",con );
    SqlDataAdapter da = new SqlDataAdapter(cmd );
    DataTable dt = new DataTable();
    da.Fill(dt );

    dataGridView1.Rows.Clear();
    foreach (DataRow item in dt.Rows )
    {
    int n = dataGridView1.Rows.Add();
    dataGridView1.Rows[n].Cells[0].Value = item[0].ToString();
    dataGridView1.Rows[n].Cells[1].Value = item[1].ToString();

    }
    }

    ReplyDelete

MM Online Express | Best product Review and Online Marketing site

MM Online Express | Best product Review and Online Marketing site