iT邦幫忙

0

sql查詢時大括弧的意思

string SqlStr = string.Format(@"select * from Animal where Dog_ID='{1}' and Cat_ID = '{3}'", DogName.Text, CatName.Text);

如上
最近在自學程式語言的資料庫
可是我不懂DogID和CatID後面**'{1}'及'{3}'意思**
谷哥也不知道該下什麼關鍵字
煩請大大說明
謝謝

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

2
Yaowen
iT邦研究生 4 級 ‧ 2021-11-28 03:55:15
最佳解答

這個跟SQL無關 是C#的東西

string s = String.Format("At {0}, the temperature is {1}°C.",
DateTime.Now, 20.4);
Console.WriteLine(s);
// Output similar to: 'At 4/10/2015 9:29:41 AM, the temperature is 20.4°C.'

{0} = DateTime.Now
{1} = 20.4

字串格式方法請參考下方網址
MSDN

原來如此,謝謝大大

2
qpowjohn
iT邦新手 4 級 ‧ 2021-11-28 12:42:24

雖然是題外話,但建議改用參數化查詢,較不會產生SQL injection

C# 使用參數化查詢解決拼接字符串產生的漏洞攻擊

謝謝提供相關資料

我要發表回答

立即登入回答