Read just one row (primary key) and display each column of the row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeafSmith
    New Member
    • Aug 2015
    • 6

    Read just one row (primary key) and display each column of the row

    I am using Postgresql in VS 2013 and C#.

    I use this for the reading of just one row by primary key.

    string p has the users id it must look for in the table.

    Code:
     cn.Open();
     selectSql = "SELECT user_id,user_name,user_password,user_administrator FROM userlogon WHERE user_id ='" + p + "'";
     cmd.CommandText = selectSql;
     NpgsqlDataAdapter da = new NpgsqlDataAdapter(selectSql, conn);
     NpgsqlCommandBuilder cdb = new NpgsqlCommandBuilder(da);
     DataSet ds = new DataSet();
     DataTable dt = new DataTable();
     ds.Reset();
     da.Fill(ds);                 
     dt = ds.Tables[0];
    I now want the first column of the row to be moved to another string like:

    Code:
    got_userID = dt.Columns[0].ToString();
    But all I get is literally the field's name, 'user_id' in got_userID when I display it via messageBox.Show !

    Any idea why?

    Thanks!
Working...