468,119 Members | 2,086 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

C# Error with a Concatenated SQL query...

Hello,

I haven't posted here in a long time, but the last time I got excellent
advice. Hope someone can help again because I'm really stumped...

I have been having trouble with the following SQL query in a C# app:

sqlSelectCommand1.CommandText="Select ServerName + '.' + DBName AS
ServerDBName From TestDBList(nolock)Where ServerName
=('oemsitsql01')Order By ServerDBName";

When I run this in SQL Query Analyzer it runs fine:

Select ServerName + '.' + DBName AS ServerDBName From
TestDBList(nolock)Where ServerName =('oemsitsql01')Order By ServerDBName

But when I put it in C# it compiles fine, but on page load I get the
following error:

Server Error in '/WebApplication1' Application.
------------------------------------------------------------------------
--------

Failed to enable constraints. One or more rows contain values violating
non-null, unique, or foreign-key constraints.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.ConstraintException: Failed to enable
constraints. One or more rows contain values violating non-null, unique,
or foreign-key constraints.

Source Error:
Line 130: //sqlSelectCommand1.CommandText= "Select Into
#TempServerDBList ServerName + '.' + DBName AS ServerDBName From
TestDBList(nolock)Where ServerName In('" +
ServerListBox.SelectedItem.Value + "')Order By ServerDBName Select *
From #TempServerDBList";
Line 131://"Select distinct DBName From TestDBList(nolock)Where
ServerName ='" + ServerListBox.SelectedItem.Value + "'";
Line 132: sqlDataAdapter1.Fill(DBDataSet1);
Line 133: DBListBox.DataBind();
Line 134:
Any assistance much appreciated.
Thanks,
Jeff
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
0 1919

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Polar | last post: by
2 posts views Thread by Michelle | last post: by
JavaStudent07
2 posts views Thread by JavaStudent07 | last post: by
14 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.