Null values in a DataColumn.PrimaryKey column

S

ScottSto

I am working with a DataTable.PrimaryKey field. I have two fields,
Address1 and Address2. The underlying database field for Address2 can
contain null values, and this is causing me problems - I get a "Column
'ADDRESS2' has null values in it" error. Is it possible to add a column
that may (and probably will) have nulls in the PrimaryKey? I have a
workaround in mind, but I just want to be sure before I try it.

Thanks,
Scott
 
M

Miha Markic [MVP C#]

Hi Scott,

Having null values in primary key column doesn't make any sense - it could
lead you to duplicates
 
S

Sahil Malik [MVP]

Can you have only one null value that way?

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
-------------------------------------------------------------------------------------------

Miha Markic said:
Hi Scott,

Having null values in primary key column doesn't make any sense - it could
lead you to duplicates

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

ScottSto said:
I am working with a DataTable.PrimaryKey field. I have two fields,
Address1 and Address2. The underlying database field for Address2 can
contain null values, and this is causing me problems - I get a "Column
'ADDRESS2' has null values in it" error. Is it possible to add a column
that may (and probably will) have nulls in the PrimaryKey? I have a
workaround in mind, but I just want to be sure before I try it.

Thanks,
Scott
 
S

ScottSto

In my case, null values are a valid option for the Address2 field. The
Address1 field will never accept nulls. These are a few possibilites
for acceptable data:

Address1: 123 Main Street
Address2: <null>

Address1: 123 Main Street
Address2: Apt 1

Address1: 123 Main Street
Address2: Apt 2

Thanks,
Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top