码迷,mamicode.com
首页 > 数据库 > 详细

C# 在把变量嵌入SQL中

时间:2017-06-21 18:21:57      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:convert   com   name   使用   嵌入   mysq   form   .text   logs   

1、使用 ‘ " +    + " ‘ 拼接

string mysql = 
    "SELECT Cname,Grade 
      FROM student,score,course 
      WHERE student.Sno = score.Sno and 
                  score.Cno = course.Cno and 
                  student.Sno = ‘" + Convert.ToString(textBox1.Text) + "’ and         
                  score.Text =‘" + Convert.ToInt32(comboBox1.Text) + “’;
    ”; 

2、使用占位符

string mysql = string.Format(
    "SELECT Cname,Grade 
     FROM student,score,course 
     WHERE student.Sno = score.Sno and 
                score.Cno = course.Cno and 
                student.Sno = {0} and 
                score.Text = ‘{1}‘ " ,
    textbox1.Text,ComboBox1.Text);    

 

C# 在把变量嵌入SQL中

标签:convert   com   name   使用   嵌入   mysq   form   .text   logs   

原文地址:http://www.cnblogs.com/huangj/p/7060771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!