2013-02-22 40 views
0

我想把我的字符串放到幾行中。我怎麼能這樣做? 這是我想要剪切的代碼行(但它們仍然是字符串)。如何把另一行字符串(仍然在一個短語中)在vb.net?

sql = "INSERT INTO tblClientInfo (genClientID, fullName, address, comaker, colateral, atmPIN, principal, " 
       & "interest, principalInWords, terms, interestPerMonth, principalperMonth, totalPayment, interestPercentage, " 
       & " interestBal, principalBal, theDate, totalBal)" 

此代碼返回錯誤。串聯或切割長串的正確方法是什麼?

+0

你之後的燕尾是「連續字符」。 http://msdn.microsoft.com/en-us/library/aa711641(v=vs.71).aspx – 2013-02-22 03:22:08

回答

2

您需要指示該行的後面添加每一行與一個空格下劃線繼續延續到下一行,如下所示:

sql = "INSERT INTO tblClientInfo (genClientID, fullName, address, comaker, colateral, atmPIN, principal, " _ 
    & "interest, principalInWords, terms, interestPerMonth, principalperMonth, totalPayment, interestPercentage, " _ 
    & " interestBal, principalBal, theDate, totalBal)" 

附加參考:http://msdn.microsoft.com/en-us/library/aa711641%28v=vs.71%29.aspx

+0

所以這就是它應該如何。很好說謝謝! – 2013-02-22 03:37:11

0

我像String.Concat(),因爲你不需要連續下劃線,你不需要&符號。看起來更乾淨。

sql = String.Concat( 
    "INSERT INTO tblClientInfo (genClientID, fullName, address, comaker, colateral, atmPIN, principal, ", 
    "interest, principalInWords, terms, interestPerMonth, principalperMonth, totalPayment, interestPercentage, ", 
    "interestBal, principalBal, theDate, totalBal)") 
+0

它返回語法錯誤...但我喜歡這個想法,如果它工作 – 2013-02-22 03:34:52

+0

@JayMarz奇怪的是,它爲我工作。只要定義了'sql'。 – ThinkingStiff 2013-02-22 03:41:59

+0

我不知道。也許有什麼東西需要導入或什麼。 – 2013-02-22 03:55:19

相關問題