is this possible instead of an incrementing ID number, I have GUID in the code instead?
+1
A:
Certainly, check here:
http://msdn.microsoft.com/en-us/library/system.data.datatable.primarykey(VS.71).aspx
// Create a new DataTable and set two DataColumn objects as primary keys.
DataTable myTable = new DataTable();
DataColumn[] keys = new DataColumn[1];
DataColumn myColumn = new DataColumn();
myColumn.DataType = System.Type.GetType("System.Guid");
myColumn.ColumnName= "ID";
// Add the column to the DataTable.Columns collection.
myTable.Columns.Add(myColumn);
keys[0] = myColumn;
// Set the PrimaryKeys property to the array.
myTable.PrimaryKey = keys;
CSharper
2010-01-18 04:54:47
the PrimaryKey attribute is a DataColumn[], im getting an errror from your code.
Martin Ongtangco
2010-01-18 05:30:49
sorry, give that a shot. It's an array because you can set a multi-column primary key.
CSharper
2010-01-18 05:35:19
Excellent, it works! thanks man!
Martin Ongtangco
2010-01-18 05:41:19
A:
One option is to normally have the value of the primary key as NEWID() to assign GUID to a variable declared as the uniqueidentifier data type
The other option is to have sequential GUIDs using this NEWSEQUENTIALID() function available in sqlserver. However MSDN states: If privacy is a concern, do not use this function. It is possible to guess the value of the next generated GUID and, therefore, access data associated with that GUID.
Example of SqlQuery using newid()
CREATE TABLE cust
(
CustomerID uniqueidentifier NOT NULL
DEFAULT newid(),
Company varchar(30) NOT NULL,
ContactName varchar(60) NOT NULL,
Address varchar(30) NOT NULL,
City varchar(30) NOT NULL,
StateProvince varchar(10) NULL,
PostalCode varchar(10) NOT NULL,
CountryRegion varchar(20) NOT NULL,
Telephone varchar(15) NOT NULL,
Fax varchar(15) NULL
)
Kavitesh Singh
2010-01-18 05:51:05