日期:2014-05-18  浏览次数:20502 次

虽然已经解决,但很想知道原因!
private   void   Page_Load(object   sender,   System.EventArgs   e)
{
//   在此处放置用户代码以初始化页面
if   (Request.Params[ "Id "]   !=   null)  
{
itemId   =   Int32.Parse(Request.Params[ "Id "]);
             
}
if   (itemId   !=   0)  
{
OleDbConnection   objConn=new   OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;   Data   Source= "   +    
Server.MapPath( "../mydatabasermvb.mdb "));    
string   SQL= "select   *   from   [news]   where   id   like   ' "+itemId   + " ' "   ;
OleDbDataAdapter   objCommand=new   OleDbDataAdapter(SQL,objConn);    
DataSet   ds=new   DataSet();    
objCommand.Fill(ds, "news ");    
this.DataGrid1.DataSource   =   ds.Tables[ "news "].DefaultView;  
this.DataGrid1.DataBind();

string   SQL= "select   *   from   [news]   where   id   like   ' "+itemId   + " ' "   ;这一句用like就可以显示出来而string   SQL= "select   *   from   [news]   where   id= ' "+itemId   + " ' "
就数据库为空。第一次提问,谢谢大家


------解决方案--------------------
id是整型就应该这样写
string SQL= "select * from [news] where id= " + itemId
如果是string就没必要这样
itemId = Int32.Parse(Request.Params[ "Id "]);
转型了
,如果是string
string SQL= "select * from [news] where id like ' "+itemId.Trim() + " ' " ;//把两边空字符去掉