试图连接字符串但得到错误

时间:2011-07-04 12:43:23

标签: mysql sql

HI我正在尝试连接字符串,但我在此行收到错误

sql += " "+"WHERE memberToMship_PayMethod="' +Cash"'";

像字符文字中的字符太多......

任何人都可以帮忙......

                              sql = @"SELECT members.member_Id, members.member_Lastname, members.member_Firstname, members.member_IsBiometric";
  sql += ","+"members.member_Reference, members.member_Dob, members.member_PostCode, mshipstatustypes.mshipStatusType_Name, mshiptypes.mshipType_Name";
  sql += ","+"membertomships.memberToMship_EndDate";
  sql += " "+"FROM members LEFT JOIN membertomships ON membertomships.member_Id = members.member_Id";
  sql += " "+"LEFT JOIN mshipstatustypes ON mshipStatusType_Id = membertomships.mshipStatusType_Id";
  sql += " "+"LEFT JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id";
  sql += " "+"LEFT JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id";
  sql += " "+"WHERE memberToMship_PayMethod="' +Cash"'";

4 个答案:

答案 0 :(得分:1)

sql += " "+"WHERE memberToMship_PayMethod="' +Cash"'";

应该是

sql += " "+"WHERE memberToMship_PayMethod='" +Cash+ "'";

sql += " "+"WHERE memberToMship_PayMethod='Cash'";

答案 1 :(得分:0)

你的引号之外的双引号,你错过了+。试试这个:

sql += " "+"WHERE memberToMship_PayMethod='" + Cash + "'"; 

答案 2 :(得分:0)

尝试

     sql = @"SELECT members.member_Id, members.member_Lastname, members.member_Firstname, members.member_IsBiometric";
  sql += ","+"members.member_Reference, members.member_Dob, members.member_PostCode, mshipstatustypes.mshipStatusType_Name, mshiptypes.mshipType_Name";
  sql += ","+"membertomships.memberToMship_EndDate";
  sql += " "+"FROM members LEFT JOIN membertomships ON membertomships.member_Id = members.member_Id";
  sql += " "+"LEFT JOIN mshipstatustypes ON mshipStatusType_Id = membertomships.mshipStatusType_Id";
  sql += " "+"LEFT JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id";
  sql += " "+"LEFT JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id";
  sql += " "+"WHERE memberToMship_PayMethod='" + "Cash" + "'";

答案 3 :(得分:0)

实际上您不需要联系,您的查询很简单,因此您可以使用:

sqlQuery = @"Select * from ...........
..........................
where CashMethod="+Cash;