C#中查询数据库
string sql="select * from zonghe where barcode=region"
zonghe为数据表名,在数据表中barcode列的类型为nchar(10),region为string类型,通过switch语句赋值
请问 我这样做有什么错误

解决方案 »

  1.   

    加单引号:
    string sql="select * from zonghe where barcode= ‘region’"
      

  2.   

    如你所说,加单引号之后还是不能把region的内容准确的传入啊
      

  3.   

    string sql="select * from zonghe where barcode= ‘"+region+"’"
      

  4.   

    string sql=string.Format("select * from zonghe where barcode= '{0}'",region);
      

  5.   

    string sql="select * from zonghe where barcode=@region"
    comm1.Parameters.AddWithValue("@region", region);
      

  6.   

    数据库里执行string sql="select * from zonghe where barcode= ‘region’"是神马结果捏
      

  7.   

    string sql="select * from zonghe where barcode="+region