这句话的单引号什么意思?SqlCommand cmd = new SqlCommand("select * from login where username = '" + this.TextBox1.Text.Trim() + "'"

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/02 06:59:15
这句话的单引号什么意思?SqlCommand cmd = new SqlCommand(

这句话的单引号什么意思?SqlCommand cmd = new SqlCommand("select * from login where username = '" + this.TextBox1.Text.Trim() + "'"
这句话的单引号什么意思?
SqlCommand cmd = new SqlCommand("select * from login where username = '" + this.TextBox1.Text.Trim() + "'"

这句话的单引号什么意思?SqlCommand cmd = new SqlCommand("select * from login where username = '" + this.TextBox1.Text.Trim() + "'"
这句话被编译的结果是 select * from login where username =‘文本框里的内容’ 这个单引号是给数据库使用的是T-SQL语句的要求,把上面的语句可以拆写成这样
string sql="select * from login where username = '" + this.TextBox1.Text.Trim() + "'";
SqlCommand cmd = new SqlCommand(sql);
这样的话就是一个在C#中出现的T-SQL语句了,他是一个待定查询条件的T-SQL语句因为username=的值是输入的是不确定的,数据库为了区分引号跟程序中的引号所以使用的是单引号,这样可以保证在程序跟T-SQL语句中的区分