我是Web服务的新手,我写了一些简单的查询。他们工作正常,但是这不会返回JSON
SqlDataReader dr;
SqlCommand cmd = new SqlCommand("SELECT * FROM doctors WHERE address LIKE %@add%", conn);
cmd.Parameters.AddWithValue("@add", address);
dr = cmd.ExecuteReader();
如果我像
键入它"select * from doctors WHERE address = @add
它的工作正常
似乎是什么问题?
将%添加到值,而不是参数名称
var address = "%1 main street%";
SqlDataReader dr;
SqlCommand cmd = new SqlCommand("SELECT * FROM doctors WHERE address LIKE @add", conn);
cmd.Parameters.AddWithValue("@add", address);
dr = cmd.ExecuteReader();
尝试此
SqlDataReader dr;
SqlCommand cmd = new SqlCommand("SELECT * FROM doctors WHERE address LIKE '%@add%'", conn);
cmd.Parameters.AddWithValue("@add", address);
dr = cmd.ExecuteReader();