他的写法是这样的:
复制代码 代码如下:
view plaincopy to clipboardprint?
string strWhere = "'%美%'";
strSql = "SELECT * FROM area Where [name] like @strWhere";//这个就不好使
cmd.Parameters.AddWithValue("@strWhere", strWhere);
string strWhere = "'%美%'";
strSql = "SELECT * FROM area Where [name] like @strWhere";//这个就不好使
cmd.Parameters.AddWithValue("@strWhere", strWhere);
复制代码 代码如下:
exec sp_executesql N'SELECT * FROM Article Where [Title] like @strWhere',N'@strWhere nvarchar(5)',@strWhere=N'%为什么%'
复制代码 代码如下:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/aspxWeb.mdb;";
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
string strWhere = "%孟宪会%";
string strSql = "SELECT * FROM Document Where [Author] like @strWhere";
cmd.Parameters.AddWithValue("@strWhere", strWhere);
cmd.CommandText = strSql;
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Response.Write(dr["Author"] + " : " + dr["Title"] + "<br>");
}
con.Close();
con.Dispose();
新闻热点
疑难解答
图片精选