爱情保卫战涂磊不录了:检索数据的问题

来源:百度文库 编辑:高校问答 时间:2024/04/29 01:35:13
这两个语句有什么区别?为什么有时候用第一个语句就行,用第二个就不行,有时候用第二个行,第一个不行,具体怎么用?
sql="select * from news where news_id="&news_id

sql="select * from news where news_id='"&news_id&"'"

出现你这种情况,
是因为在数据库里面,它是有数据类型的,比如说整形,字符型等.引用字符型时必须要加单引号"'"

当news_id为整形时,则用第一条语句.即.
sql="select * from news where news_id="&news_id

当news_id为字符型时,则用第二条语句,即:
sql="select * from news where news_id='"&news_id&"'"