You must Sign In to post a response.
  • Category: ASP.NET

    how to get value of cell of datatable in c#

    how to get value of cell of datatable in c#:
    I need to get the value from datatable from eachrow in single it is?
  • #238583
    Try this,

    DataTable dt = new DataTable();
    string rowValue = dt.Rows[0].ToString();
    string coloumnValue = dt.Columns[0].ToString();

  • #238584

    //Rows[0][0], first[0] means rows and second [0] means column

    Sujit Kumar

  • #238588
    try it

    if (ds1.Tables.Count > 0)
    for (int j = 0; j < ds1.Tables[0].Rows.Count; j++)
    DataRow odr = ds1.Tables[0].Rows[j];

    dataGridView1.Rows[j].Cells[1].Value = odr["columnname"].ToString();
    dataGridView1.Rows[j].Cells[2].Value = odr["columnname"].ToString();
    dataGridView1.Rows[j].Cells[4].Value = odr["columnname"].ToString();
    dataGridView1.Rows[j].Cells[2].ReadOnly = true;
    dataGridView1.Rows[j].Cells[4].ReadOnly = true;


  • #238589
    Hello Lalit,

    string cellValue = dataTable.Rows[0][1].ToString();

    Siva Prasad

  • #238752
    for (int i = 0; i < ds.Tables["reg_table"].Rows.Count; i++)
    for (int j = 0; j < ds.Tables["reg_table"].Columns.Count; j++)

    the above code will retrive a first row and all the columns,
    based on this idea please implement your code


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.