select 查询语句参数化后SqlDataReader读取不到数据啊
select 查询语句参数化后SqlDataReader读取不到数据啊请各位看看是怎么回事啊这是代码
SqlConnection aboutconn = new SqlConnection(conn);
aboutconn.Open();
SqlCommand comm = new SqlCommand("select * from news where Items='@Membership'", aboutconn);
// comm.Parameters.AddWithValue("Items", "Membership");
SqlParameter sp = new SqlParameter("@Membership", SqlDbType.NVarChar);
sp.Value = "Membership";
comm.Parameters.Add(sp);
SqlDataReader rd = comm.ExecuteReader();
StringBuilder sb = new StringBuilder();
sb.Append("<div class='title' style='font-size:16px;width:670px;'>");
while(rd.Read()){
sb.Append("<div style='margin-top:20px;'><a style='text-decoration:none;'>" + rd["titles"].ToString() + "</a></div>");
sb.Append("<div style='margin-top:20px;width:670px ;word-wrap:break-word ;'>" + rd["contents"].ToString() + "</div>");
}
sb.Append("</div>");
rd.Close();
info.InnerHtml = sb.ToString();
aboutconn.Dispose();
aboutconn.Close();
嗷嗷嗷222
div
------解决方案--------------------数据库里有这条记录吗?
另外参数化的sql语句,不需要在参数两边加单引号,你把单引号去掉试试
SqlCommand comm = new SqlCommand("select * from news where Items=@Membership", aboutconn);