Hi every one

I'm trying to retrieve UserID (which is autonumber in ms access database) using C# and assign it to string u.I'm totally new to C# and trying to get more skills....

here goes..

 string connStr, selectCmd;
                connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\\library.accdb";
                selectCmd = "SELECT * FROM users WHERE First_Name ='x' AND Last_Name = 'y'";
                OleDbConnection conn;
                OleDbDataAdapter myAdapter;
                DataSet myDataSet = new DataSet();
                conn = new OleDbConnection(connStr);
                myAdapter = new OleDbDataAdapter(selectCmd, conn);
                myAdapter.Fill(myDataSet, "users");
                u = myDataSet.Tables["users"].Columns[0].ToString();

All i'm getting at the end is name of the column in that table...but not the actual value

The column you are retrieving from the "users" table is the entire column of your result (not pertaining to a single row). You'll need to use the DataTable.Rows property instead. Then, use the DataRow.Item property to access the appropriate column. FYI, I would think it's better practice to use the column name instead of the column index.

Thanks ... I've found easier way to get that done, but I thing something is wrong with my query...

"SELECT items.carrier, items.author, items.item_name,  Hires.when_hired FROM (Hires INNER JOIN items ON Cstr(Hires.ItemID) = Cstr(items.ItemID))WHERE Hires.UserID = 'u'"

If any one could tell what have i done wrong that would be great..
Thanks in advanced

Never mind... got that working as well...:-) (It was type mismatch in Heres.userid and u..If anyone interested - fixed by adding Cstr(Hires.UserID) and that's it) Thanks !!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.