1

これはばかげていますが、sqlcommand の sql 文字列を宣言していて、すべてを 1 行で次のように記述する必要があります

string strSQL = "SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],RTRIM(Name)+' '+   RTRIM(initial) as Name,[Own Hours],[Other Hours],[Total Hours],[OT Premium] FROM [Wages].[CHHours] Where [Year]=@WageYear and [Week No]=@Week Order by  [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

そうしないと、改行が常にエラーになりますが、これは本当に見苦しく、読みにくいように見えます。vb では &_ を使用して続行し、c# は空白に敏感ではないため (私は思っていました)、このように記述する必要があります。

string strSQL = "SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],
              RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours],[Other Hours],
               [Total Hours],[OT Premium] 
               FROM [Wages].[CHHours] 
               Where [Year]=@WageYear and [Week No]=@Week 
               Order by  [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

または私はする必要がありますか

string strSQL = "SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],";

string strSQL = strSQL+" RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours]";

string strSQL = strSQL+",[Other Hours],[Total Hours],[OT Premium] ";

string strSQL = strSQL+"FROM [Wages].[CHHours] ";

string strSQL = strSQL+" Where [Year]=@WageYear and [Week No]=@Week ";

string strSQL = strSQL+"Order by  [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

とても古いものだと思います。

イアンを喜ばせる最善の方法は何ですか

4

4 に答える 4

6

@ 記号を使用します。

string strSQL = @"SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],
         RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours],[Other Hours],
           [Total Hours],[OT Premium] 
           FROM [Wages].[CHHours] 
           Where [Year]=@WageYear and [Week No]=@Week 
           Order by  [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

それはうまくいくかもしれませんか?

于 2013-10-25T12:23:09.597 に答える
1

これはどう:

string strSQL = "SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No]," 
                + " RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours]" 
                + ",[Other Hours],[Total Hours],[OT Premium] "
                + "FROM [Wages].[CHHours] "
                + " Where [Year]=@WageYear and [Week No]=@Week " 
                + "Order by [Year] DESC, [Week No] DESC,Dept,[Clock No]";
于 2013-10-25T12:24:45.007 に答える
0

テキスト ボックスからクエリに情報を追加する場合は、2 つの組み合わせを使用できます。このようなもの

string strSQL = "SELECT [Year],[Week No],StartDate,EndDate,Dept,'" + textBox1.Text +  "'[Clock No],"
 +@" RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours]
 ,[Other Hours],[Total Hours],[OT Premium] 
 FROM [Wages].[CHHours] 
 Where [Year]=@WageYear and [Week No]=@Week  
 Order by [Year] DESC, [Week No] DESC,Dept,[Clock No]";
于 2013-12-13T16:16:30.700 に答える
0
string strSQL = @"SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],
     RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours],[Other Hours],
       [Total Hours],[OT Premium] 
       FROM [Wages].[CHHours] 
       Where [Year]=@WageYear and [Week No]=@Week 
       Order by  [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

//Now replace the @... with your desired data
strSQL = strSQL.Replace("@WageYear",your year).Replace("@Week ",your week);

//Or in multiple lines
strSQL = strSQL.Replace("@WageYear",your year);
strSQL = strSQL.Replace("@Week ",your week);

お役に立てれば

于 2013-10-25T12:52:02.870 に答える