By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

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

P: 6
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.

Expand|Select|Wrap|Line Numbers
  1.  cn.Open();
  2.  selectSql = "SELECT user_id,user_name,user_password,user_administrator FROM userlogon WHERE user_id ='" + p + "'";
  3.  cmd.CommandText = selectSql;
  4.  NpgsqlDataAdapter da = new NpgsqlDataAdapter(selectSql, conn);
  5.  NpgsqlCommandBuilder cdb = new NpgsqlCommandBuilder(da);
  6.  DataSet ds = new DataSet();
  7.  DataTable dt = new DataTable();
  8.  ds.Reset();
  9.  da.Fill(ds);                 
  10.  dt = ds.Tables[0];           
I now want the first column of the row to be moved to another string like:

Expand|Select|Wrap|Line Numbers
  1. 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?

Oct 16 '15 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.