C# breaking up long lines of code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Newbie19
    New Member
    • Jun 2007
    • 122

    C# breaking up long lines of code

    I've searched a few websites and none of them meantion how to break up really long lines of code like a sql query.

    The sql statement looks like this (I've broked it down so it can fit in the post):
    String sSQL = "SELECT dbo.Issues.Crea tedDate as Created, dbo.Issues.Modi fiedDate as Modified, dbo.Issues.Fiel d1 AS Repro, dbo.Issues.Fiel d3 AS Notes dbo.Issues.Fiel d2 as Priority, dbo.Issues.Fiel d11 AS Build, dbo.Issues.Fiel d12 as Description, dbo.Issues.Fiel d25 AS VersionIn, dbo.Issues.Fiel d26 As VersionFixed dbo.Issues.ID,d bo.Types.Name AS Type, dbo.Issues.Syno psis dbo.States.Name AS State, dbo.States.ID AS StatesID, dbo.Users.Name AS [User], dbo.Projects.Na me AS Projects FROM dbo.Issues INNER JOIN dbo.Projects ON dbo.Issues.Proj ectID = dbo.Projects.ID INNER JOIN dbo.States ON dbo.Issues.Stat eID = dbo.States.ID INNER JOIN dbo.Types ON dbo.Issues.Type ID = dbo.Types.ID INNER JOIN dbo.Users ON dbo.Issues.Assi gnedUserID = dbo.Users.ID WHERE ( dbo.Projects.ID = 66)";

    I'm not sure if this post should be here, but I figured it is worth a shot. Thanks for any advice.
    Newbie19
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You shouold be able to:
    [code=c#]
    String sSQL = "SELECT dbo.Issues.Crea tedDate as Created,"
    + " dbo.Issues.Modi fiedDate as Modified,"
    + " dbo.Issues.Fiel d1 AS Repro,"
    + " dbo.Issues.Fiel d3 AS Notes dbo.Issues.Fiel d2 as Priority,"
    +etc....
    [/code]

    Comment

    • Newbie19
      New Member
      • Jun 2007
      • 122

      #3
      Originally posted by weaknessforcats
      You shouold be able to:
      [code=c#]
      String sSQL = "SELECT dbo.Issues.Crea tedDate as Created,"
      + " dbo.Issues.Modi fiedDate as Modified,"
      + " dbo.Issues.Fiel d1 AS Repro,"
      + " dbo.Issues.Fiel d3 AS Notes dbo.Issues.Fiel d2 as Priority,"
      +etc....
      [/code]
      Thank you very much, C# is more like Java then I realized.

      Thanks again,

      Newbie19

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Originally posted by Newbie19
        Thank you very much, C# is more like Java then I realized.

        Thanks again,

        Newbie19
        You can also do:
        Code:
        String sSQL = "";
        sSQL += "SELECT dbo.Issues.CreatedDate as Created,";
        sSQL += " dbo.Issues.ModifiedDate as Modified,"
        sSQL += " dbo.Issues.Field1 AS Repro,"
        sSQL += " dbo.Issues.Field3 AS Notes dbo.Issues.Field2 as Priority,"
        //sSQL += etc....
        (There is a "cost" with this as it re-creates the string everytime.)

        Comment

        • camel
          New Member
          • Jan 2008
          • 55

          #5
          If you are going to need a lot of concatenations best option is likely the System.Text.Str ingBuilder which overcomes the performance issues of +=

          Comment

          Working...