首页 > 数据库技术 > 详细

C# 在把变量嵌入SQL中

时间:2017-06-21 17:50:43      阅读:300      评论:0      收藏:0      [点我收藏+]

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中

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!