无法将类型"int"隐式转换为"string"

luoyifh 2008-06-04 03:48:50
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
if(Request.QueryString["ID"]!=null&& Request.QueryString["ID"].Length>0)
ID=int.Parse(Request.QueryString["ID"]);
string connectionString=ConfigurationSettings.AppSettings["connectionString"];
SqlConnection con=new SqlConnection(connectionString);
con.Open();

string Sql="select * from S_News where ID=" +ID;
SqlCommand com=new SqlCommand(Sql,con);
SqlDataReader reader=com.ExecuteReader();
if(reader.Read())
{
lTitle.Text=reader["Title"].ToString();
lAdduser.Text=reader["Adduser"].ToString();
lAddtime.Text=reader["Addtime"].ToString();
}
else
{
lresult.Text="没有找到相应的信息";
}
reader.Close();
con.Close();
}
}
...全文
123 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Janyue 2008-06-04
  • 打赏
  • 举报
回复
看看
xiaoyasheng 2008-06-04
  • 打赏
  • 举报
回复
楼主可以结贴了哦
nsonline 2008-06-04
  • 打赏
  • 举报
回复
int ttt = int.Parse(Request.QueryString["ID"].ToString());

这样就没问题了, int.Parse要求跟的是string类型参数
jinjazz 2008-06-04
  • 打赏
  • 举报
回复
int ttt = int.Parse(Request.QueryString["ID"]); 


一定不会抱错,你把自己的数据类型先搞清楚
luoyifh 2008-06-04
  • 打赏
  • 举报
回复
ID是int
优途科技 2008-06-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ericzhangbo1982111 的回复:]
ID=Request.QueryString["ID"].ToString();

你的id是string类型
为什么要转换成Int 类型呢?
[/Quote]
我姓区不姓区 2008-06-04
  • 打赏
  • 举报
回复
ID是int还是string?
luoyifh 2008-06-04
  • 打赏
  • 举报
回复
知道了,谢谢两位啊
ericzhangbo1982111 2008-06-04
  • 打赏
  • 举报
回复
ID=Request.QueryString["ID"].ToString();

你的id是string类型
为什么要转换成Int 类型呢?
jinjazz 2008-06-04
  • 打赏
  • 举报
回复
ID是string类型?
ID= Request.QueryString["ID"] ;

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧