C# Error with a Concatenated SQL query...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Martin

    #1

    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:

    sqlSelectComman d1.CommandText= "Select ServerName + '.' + DBName AS
    ServerDBName From TestDBList(nolo ck)Where ServerName
    =('oemsitsql01' )Order By ServerDBName";

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

    Select ServerName + '.' + DBName AS ServerDBName From
    TestDBList(nolo ck)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.Con straintExceptio n: Failed to enable
    constraints. One or more rows contain values violating non-null, unique,
    or foreign-key constraints.

    Source Error:


    Line 130: //sqlSelectComman d1.CommandText= "Select Into
    #TempServerDBLi st ServerName + '.' + DBName AS ServerDBName From
    TestDBList(nolo ck)Where ServerName In('" +
    ServerListBox.S electedItem.Val ue + "')Order By ServerDBName Select *
    From #TempServerDBLi st";
    Line 131://"Select distinct DBName From TestDBList(nolo ck)Where
    ServerName ='" + ServerListBox.S electedItem.Val ue + "'";
    Line 132: sqlDataAdapter1 .Fill(DBDataSet 1);
    Line 133: DBListBox.DataB ind();
    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!
Working...