Get primary key values in Table Adapter

Asked

Viewed 85 times

1

How can I get all primary key values in one Table Adapter.

One by one I can get at the time of the Insert with this code:

PegaIdOrc = orcTableAdapter.GetDataByMaxIDOrc().
            Rows[0]["Expr1"].ToString();

But when I try to get all the values of a query, returns me the pre-insertion numbers like this: -1, -2, -3...

I’ve tried a foreach with the line count, but the return are always these negative numbers.

  • How are you doing Insert? and which database is using?

  • Marconcilio, the problem does not happen during the Insert, but rather, when datagridview already contains the query items. I already managed to change the query so that the id’s are presented in a column with alias and I was able to get all id’s doing a foreach in Datagridview. What is still disturbing is the last blank line that the DGV generates automatically returning me to zero. BD is Access.

  • Let me get this straight, you have a datagridview that recover the ids from it is this? is coreto Windows.Forms application?

  • The id’s that I want to recover are the primary query keys of BD items that populate Datagridview and make up the zero index column. Yes, it’s Windows.Forms. At this point I already managed to make the code work with the command I informed in the comment above and I have done the procedure to ignore the last empty line that the DGV generates automatically, checking if the field has null value. I’ll leave the topic open for a while, maybe a better solution will come up.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.