switch(Request.QueryString["flag"].ToString())
{
case "1":
sqlstr="select vhostprice,id from [v-host] where id="+id.ToString();
break;
case "2":
break;
case "3":
break;
case "4":
sqlstr="select postprice,id from post-host where id="+id.ToString();
break;
default:
break;
}
SqlDataAdapter myad=new SqlDataAdapter(sqlstr,myconn);
如我上面所写的
提示:Invalid object name 'v-host'. 这个表是存在的,而且 我在其它地方也是这用写的SQL语句,不知道为什么在这里就出错了。
{
case "1":
sqlstr="select vhostprice,id from [v-host] where id="+id.ToString();
break;
case "2":
break;
case "3":
break;
case "4":
sqlstr="select postprice,id from post-host where id="+id.ToString();
break;
default:
break;
}
SqlDataAdapter myad=new SqlDataAdapter(sqlstr,myconn);
如我上面所写的
提示:Invalid object name 'v-host'. 这个表是存在的,而且 我在其它地方也是这用写的SQL语句,不知道为什么在这里就出错了。
V-host是表名
不加中括号的话,会是不合法的,也会出错
去掉中括号的话
提示“Line 1: Incorrect syntax near '-'. ”
如果数据库中id真的是字符串类型的话,那么语句应该这样写:
sqlstr="select vhostprice,id from [v-host] where id='"+id.ToString()+"'";
我有两个数据库连接语句,我选错了。
真不好意思,各位兄弟 谢谢你们。
ID是INT 型的
sqlstr="select vhostprice,id from [v-host] where id="+id.ToString();
这样写SQL语句也不会出错。