SqlString = "SELECT Pub_Users.LogId,Obj_staff.StaffId,Obj_staff.StaffName,Pub_Roles.RoleName"
                                    + " FROM Pub_Users,Obj_staff,Pub_UserRole,Pub_Roles"
                                    + " WHERE Pub_Users.StaffId=Obj_staff.StaffId"
                                    + " and Pub_Users.LogId=Pub_UserRole.LogId"
                                    + " and Pub_UserRole.RoleId=Pub_Roles.RoleId"
                                    + " and Pub_Roles.RoleName LIKE ?";
                SqlCommand sc = new SqlCommand();
                SqlParameter myParameter = new SqlParameter("@role", SqlDbType.Text, 10);
                sc.Parameters.Add(myParameter);

解决方案 »

  1.   

    http://www.cnblogs.com/xiaozhuoyun/archive/2008/01/24/1051313.htmllike参数查询 
    在做项目的时候遇到使用like参数查询,结合网上的例子..下面是常用的方法...测试成功
     public static DataSet GetQuestionsBySubject(string subject)
            {
                if (string.IsNullOrEmpty(subject))
                    return null;            StringBuilder strb = new StringBuilder("select * from Question where subject like N'%'+@subject+'%'");
                List<SqlParameter> list_Params = new List<SqlParameter>();
                list_Params.Add(new SqlParameter("@subject", subject));;
                return DBUtility.SqlHelper.ExecuteDataSet(new SqlConnection(Access.ConnectionString), strb.ToString(), list_Params.ToArray()); 
            }
    注意 : SQL 语句的写法 like N'%'+@subject+'%'  都是单引号
      

  2.   


    ? 那是ado的写法,这里要明确给出参数名...