oledbcommand的问题

houjianxun 2002-09-05 03:10:39
我想打开表中的一行之前,先根据返回的ID更新一下,然后再打开,应该怎么做呢?
这样放两个oledbcommand在一起是不行??

以下内容为程序代码,可是却有错误:

dim upcomm As New oledbcommand("update article set hits=hits+1 where ID="& id ,myconn)
upcomm.executenonquery()
upcomm.close()
Dim mycomm As New oledbcommand("select * from article where articleid="& id ,myconn)
Dim dr As oledbdatareader = mycomm.Executereader()
If dr.read() Then
.......
end if

...全文
215 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
houjianxun 2002-09-10
  • 打赏
  • 举报
回复
谢谢,我刚学习.net,只做了一个文章管理的

演示:http://lionsky.net/article/index.aspx
Tongls 2002-09-10
  • 打赏
  • 举报
回复
你的数据库Conn没有连接! 你必须在Comm之后,连接好Conn,才能用!


到管理里,分分了以后,你输入你的密码,就可以给分啦! OK!
houjianxun 2002-09-10
  • 打赏
  • 举报
回复
我刚来这里不久,我不知道该怎么给你们结分,能说一下吗?
houjianxun 2002-09-10
  • 打赏
  • 举报
回复
哦,我发现是我写错了
在mycomm.executenonquery();的后面多加了一个;去掉就可以了,谢谢你们
houjianxun 2002-09-10
  • 打赏
  • 举报
回复
但是二楼的那位说的方法不可以,执行到mycomm.executenonquery();这一句就
提示:

说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。

编译器错误信息: BC30037: 字符无效。

源错误:


行 13: Dim id As integer = request.querystring("id")
行 14: dim mycomm As New oledbcommand("update article set hits=hits+1 where id="& id,myconn)
行 15: mycomm.executenonquery();


下面是我的源代码:
myconn.open()
Dim id As integer = request.querystring("id")
dim mycomm As New oledbcommand("update article set hits=hits+1 where id="& id,myconn)
mycomm.executenonquery();
mycomm As New oledbcommand("select * from article where articleid="& id ,myconn)
Dim dr As oledbdatareader = mycomm.Executereader()
If dr.read() Then
...
else
...
end if
tojike 2002-09-09
  • 打赏
  • 举报
回复
asp.net可以同时执行n条SQL语句,这是与asp显著不同的地方
zhang_dz 2002-09-06
  • 打赏
  • 举报
回复
你好

其实不需要用两个command对象,不用关闭upcomm.只要重新New一下就行了,.NET garbage collection会自动清除reference不到的对象.请看如下代码示例:

//sqlConnection1是个已建立好的connection对象.
sqlConnection1.Open();
SqlCommand cmd1 = new SqlCommand("update article set hits=hits+1 where ID ="& id, sqlConnection1);
cmd1.ExecuteNonQuery();

cmd1 = new SqlCommand("select * from article where id="& id ,sqlConnection1);
...

希望有所帮助

- 微软全球技术中心

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)
houjianxun 2002-09-06
  • 打赏
  • 举报
回复
ttt~~

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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