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

Primary Key column show null in DataGrid

P: n/a
Hi all.

I have a datagrid that has several columns including the Primary Key as
the first column.

When I add records to the grid the Primary Key column show "Null". This
would not be a problem, but I want my users to be able to delete the
column right away if they made a mistake with the entry. If the Primary
key is null I can't access the dataset to get the ID number of the row
to delete. Is there a way to refresh the datagrid immediately after
adding the row so I can see the Primary key value and not "null".
Thanks in advance.
Tom

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

Try setting a default value for the primary key column

http://msdn.microsoft.com/library/de...valuetopic.asp

Ken
-----------------------
<tr********@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all.

I have a datagrid that has several columns including the Primary Key as
the first column.

When I add records to the grid the Primary Key column show "Null". This
would not be a problem, but I want my users to be able to delete the
column right away if they made a mistake with the entry. If the Primary
key is null I can't access the dataset to get the ID number of the row
to delete. Is there a way to refresh the datagrid immediately after
adding the row so I can see the Primary key value and not "null".
Thanks in advance.
Tom
Nov 21 '05 #2

P: n/a
Thanks Ken. I read the article. Unfortunately, my datadgrid uses the
Autonumber as it's primary key. I did notice though that when I change
the values in the datagrid and then redisplay what I previously added,
the autonumber column is displayed. Is there a way to make this happen
without reopening the form? Or do I have to change the table so it
increments manually. Thanks.

Nov 21 '05 #3

P: n/a
Tom,

Your autonumber is not in the datagrid, it is in the datatable (as I assume
it normally is).

Have a look at the seed and increment from that.
http://msdn.microsoft.com/library/de...ementtopic.asp

It is adviced to set the seed to a negative value.

The official autonumber will be set at the update time, what you see is not
the real primary key.

That key is to get using a execute.scalar for the @@Identity (before you ask
it)

I hope this helps,

Cor

<tr********@yahoo.com> schreef in bericht
news:11*********************@f14g2000cwb.googlegro ups.com...
Thanks Ken. I read the article. Unfortunately, my datadgrid uses the
Autonumber as it's primary key. I did notice though that when I change
the values in the datagrid and then redisplay what I previously added,
the autonumber column is displayed. Is there a way to make this happen
without reopening the form? Or do I have to change the table so it
increments manually. Thanks.

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.