vs2008调试
string sql = "SELECT * FROM Job_ReleaseJob INNER JOIN Job_JobSort"
+ " ON Job_ReleaseJob.JobSortId = Job_JobSort.Id where Job_JobSort.Id in"
+ "(select Id from Job_JobSort where SortName like '%@SortName%')";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@SortName",sortName)
};
SqlDataReader reader = DBHelper.ExecuteDataReader(sql, para);
方法DBHelper.ExecuteDataReader如下
public static SqlDataReader ExecuteDataReader(string sql, SqlParameter[] paras)
{
return ExecuteDataReader(sql, paras, CommandType.Text);
}
public static SqlDataReader ExecuteDataReader(string sql, SqlParameter[] paras, CommandType type)
{
SqlDataReader dr = null;
//构造连接对象
SqlConnection con = new SqlConnection(str);
//构造执行对象
SqlCommand cmd = GetCommand(sql, paras, type);
cmd.Connection = con;
try
{
//打开连接
con.Open();
//执行命令
dr = cmd.ExecuteReader();
}
catch (Exception ex)
{
//输出异常
Console.WriteLine(ex.Message);
}
return dr;
}
public static SqlCommand GetCommand(string sql, SqlParameter[] paras, CommandType type)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = type;
if (paras != null)
{
cmd.Parameters.AddRange(paras);
}
return cmd;
}
SELECT * FROM Job_ReleaseJob INNER JOIN Job_JobSort ON
Job_ReleaseJob.JobSortId = Job_JobSort.Id where Job_JobSort.Id in(select Id from Job_JobSort where SortName like '%计%')在数据库查询有结果。
在网站做没搜到相应的结果出来
但没报错....好心人帮我看看哪里有错。或加我Q310500514我给源代码你
------解决方案--------------------select Id from Job_JobSort where SortName like '%@SortName%'
你确定有“@”这个符号??
------解决方案--------------------
------解决方案--------------------'%@SortName%',这个当成字符串了,把@SortName拿出来,否则不认为是参数
------解决方案--------------------