c# sql在where查询语句中使用字符串变量与int型变量

使用where语句访问数据库时where语句用上文中以及定义过的变量来查询。

string sql3 = string.Format("update Ships set ContainerNum='"+list1[0].ContainerNum+"' where Name='"+list[0].ShipName+"'");

Ships是表名  ContainerNum是表中字段名

list1[0].ContainerNum是上文的一个Int 类型变量,list[0].ShipName是上文的string类型变量

只需要在sql语句的双引号内对变量进行操作,即

(“select * from 表名  where 字段名= ‘“+ 变量名+”’    ”)

需要注意的是:‘“+ 变量名+”’  
要用两个单引号括住两个双引号

 

posted @ 2016-05-24 15:47  wumengchao1234  阅读(8605)  评论(0编辑  收藏  举报