To retrieve the column name.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bsaira
    New Member
    • Sep 2007
    • 12

    To retrieve the column name.

    Hi,

    I am coding in C#.

    I need help finding simple way to retrieve a fields (or
    columns) collection from a Dataset without filling it
    first.

    I cannot find the property of columnname.
    Please help..

    Thanks.
  • aliasruel
    New Member
    • Sep 2007
    • 73

    #2
    Hi,
    Try this code...


    DataSet1.Tables[0].Rows[0][fieldname];


    regards,
    ruel




    Originally posted by bsaira
    Hi,

    I am coding in C#.

    I need help finding simple way to retrieve a fields (or
    columns) collection from a Dataset without filling it
    first.

    I cannot find the property of columnname.
    Please help..

    Thanks.

    Comment

    • GayathriP
      New Member
      • Oct 2007
      • 17

      #3
      [code=vbnet]
      SqlConnection objconn = new SqlConnection(" server=<ServerN ame>;database=< DatabaseName>;u id=<UserID>;pwd =<Pwd>");
      objconn.Open();

      //This will not fill data as the where condition is specified as 1=2
      SqlDataAdapter sa = new SqlDataAdapter( "select query where 1=2", objconn);

      DataTable dt = new DataTable();

      sa.Fill(dt);

      for (int intLoop = 0; intLoop < dt.Columns.Coun t; intLoop++)
      {
      MessageBox.Show (dt.Columns[intLoop].ColumnName);
      }[/code]
      Last edited by Frinavale; Oct 16 '07, 07:08 PM. Reason: Added [code] tags to make more legible

      Comment

      Working...