Q:

UNIQUE Column with multiple NULL values in visual studio

I want to have a UNIQUE constraint on my Barcode column which may contain null values.
How do I create the constraint that allows multiple null values?
I use a local Database.sdf file (Microsoft SQL Server Compact 4.0 with the .NET Framework Data Provider for Microsoft SQL Server Compact 4.0).
I tried this :
SqlCeConnection con = null;
con = new SqlCeConnection(@"Data Source=|DataDirectory|\Database.sdf");
con.Open();

try
{
    SqlCeCommand cmd = con.CreateCommand();
    cmd.CommandText = "CREATE UNIQUE NONCLUSTERED INDEX Barcodex ON Products(Barcode) WHERE Barcode IS NOT NULL";
    cmd.ExecuteReader();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

but it is not working.
The error I got :

There was an error parsing the query,[Token line number =1,Token line offset =64,Token in error = WHERE]

Any help?

A:

Update: Filtered Indexes are NOT supported in SQL Server Compact 4.0
Ref: Differences Between SQL Server Compact and SQL Server
The TSQL syntax is correct. (Assuming you have SQL Server 2008+. Filtered Indexes were introduced in SQL Server 2008)
Change this:
        cmd.ExecuteReader();

to this
        cmd.ExecutNonQuery();

Also, you should wrap your connection in a using block.

