select r.BedNum,r.Roomid,r.Description,t.TypeName,s.RoomStateName
from Room r
inner join RoomType t on t.TypeId=r.RoomTypeId
inner join RoomState s on s.RoomStateId=r.RoomStateId
where r.Roomid like %@name%
SqlParameter[] para ={
new SqlParameter("@name",name)
};
怎么才能使用模糊查询?不管有没有值都能查询到内容,求大神
C#连接SQL语句问题
答案:1 悬赏:80 手机版
解决时间 2021-02-04 19:39
- 提问者网友:遮云壑
- 2021-02-04 01:08
最佳答案
- 五星知识达人网友:舍身薄凉客
- 2021-02-04 01:33
string strConn = @"data source=.;initial catalog=Northwind;integrated security=true;";
SqlConnection conn = new SqlConnection(strConn);
//关键
string sql = @"select * from employees where FirstName like @FirstName";
string fn = "%" + "ae" + "%";
SqlParameter p = new SqlParameter("@FirstName", fn);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add(p);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
SqlConnection conn = new SqlConnection(strConn);
//关键
string sql = @"select * from employees where FirstName like @FirstName";
string fn = "%" + "ae" + "%";
SqlParameter p = new SqlParameter("@FirstName", fn);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add(p);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯