C# SQL拼接字符串方式1:string SQL=' select * fromtuserwherename=' ' txt _ user.text ' ' and PSD=' ' txt _ pwd.text ' ' '; 要点:字符串中引用的字符串变量“”txt _ user.text“,”txt _ user.text“”用“…”表示。 用双引号括住单引号内容的单引号方法[ ‘? ”’,在整个字符串上加上双引号,是必不可少的。 否则报告错误。
方式二: string SQL=$ ' select * fromtuserwherename=' { txt _ user.text } ' and PSD=' { txt _ pwd.text } '; 要点:在字符串前加上$符号,中间的变量用“{内容}”表示。
方式三: string SQL=string.format (选择* fromt username=' {0} ' and PSD=' {1} ',txt_User.Text,txt_pwd推荐方式3