PRIMARY KEY required for WRITING data to SQL DATABASE using DATA G

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am posting this question here too coz I was not sure whether I had posted
this earlier in the right group.

I need an editable datagrid. But for editing a datagrid as shown in the
walkthrough: Using a DataGrid Web Control to Read and Write Data, the table
in the SQL database should have a primary key. But my table doesnt have one.
So what is the best way I can create primary key in SQL database?

Is UNIQUE IDENTIFIER a good option? Is it something like Auro Number of MS
Access which is automatically filled by the database for each row? If not ,
how can i make a primary key for that SQL table?
 
Two choices, without much pain:

UNIQUE IDENTIFIER - or GUID
IDENTITY column - integer column with IDENTITY set on

If you need a huge number of records or are spanning work across multiple
servers, the UNIQUE IDENTIFIER is better; otherwise, an integer with IDENTITY
is generally good enough (can be any type of integer column, AFAIK, although
int and bigint are most common).


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Hi Gregory,

Even when I added the identity to an int column in the database, I cant use
it for editing tha datagrid & writing the values back to the SQL database.

I am too confused at the moment.please help
 
After you added the identity column - did you make it the key? I'm guessing
the problem is that your table isn't keyed, in which case neither the
CommandBuilder or the configuration wizard is of any use for Updates.
 
Yes Ryan , the problem is that my table isnt Keyed. Thats bcoz when i try to
create a field in the table as the primary key , it is not made bcoz i get
the alert message that aTEXT DATA TYPE cant be made a primary key. I have
that field as TEXT DATA TYPE coz that filed should have voth numeric digits &
characters. Is there any other data type which supports both numeric &
character values?
 
If you use Varchar (I'm assuming you're using Sql Server?) that should work.
If not, create a composite key - one of Varchar and one of int - that'll do
it for you.
 
Back
Top