请教个简单的ASP.NET中SQL语句的标点符号
来源:百度知道 编辑:UC知道 时间:2024/06/24 08:00:16
请教个简单的ASP.NET中SQL语句的标点符号 如:
string sql = "update tb_guest_book set ReplyContent='" + TextBox2.Text.Replace("'", "''") + "',ReplyUserName='" + TextBox1.Text.Replace("'", "''") + "',ReplyTime='" + DateTime.Now.ToString() + "' where id=" + id.ToString();
其中的单引号,双引号和+怎么区分呢?
string sql = "update tb_guest_book set ReplyContent='" + TextBox2.Text.Replace("'", "''") + "',ReplyUserName='" + TextBox1.Text.Replace("'", "''") + "',ReplyTime='" + DateTime.Now.ToString() + "' where id=" + id.ToString();
其中的单引号,双引号和+怎么区分呢?
C# 字符串是用双引号的,连接符是"+",如:
string id="a"+"b"+"c"+"d"; C#, id="abcd";
Sql变量是要用单引号隔开的.比如:
select * from db where id='1'
如果要将变量引入,则必须同时遵守C#和sql的习惯,即
string sql =" select * from db where id=' " + id + " ' ";
嵌套使用时,在双引号里面的双引号要用单引号表示