(求助)ggjj帮我看看这个数据库问题,在线等待。

cplusplusman 2004-05-13 08:26:19
我连接SQL2000数据库,我在模板里用了一个公共的函数来连接数据库
Public Function connect(ByVal SQL As String, ByVal table As String)
Try
con = New SqlConnection("Server=localhost;Database=pt;Integrated Security=true")
adapter = New SqlDataAdapter(SQL, con)
ds.Clear()
ds.Tables.Clear()
adapter.Fill(ds, table)
Catch
MsgBox(Err.Description)
End Try
End Function
SQL变量是SQL语句,table是DATESET中表的名字
比如
tablename = "users"
SearchSQL = "select * from users"
connect(SearchSQL, tablename)
.........
我想更改数据,然后更新数据库,我应该怎么做比较方便?因为我没用command对象,只用到了数据适配器DataAdapter,应该怎么修改数据库比较好。毕竟我用的是一个公共的函数,要改的话其他程序还要改。谢谢!
...全文
42 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ebluesky 2004-05-14
  • 打赏
  • 举报
回复
dynamic SQL generation for the UpdateCommand is not supported against a selectcommand that does not return any key column information
的意思是:
对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成

你没有在那个表中定义主键,要定义一个主键就可以了
Vsnetlx 2004-05-14
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp
bitsbird 2004-05-13
  • 打赏
  • 举报
回复
adapter.UpdateCommand.CommandText=""
cplusplusman 2004-05-13
  • 打赏
  • 举报
回复
我用update不行呀,修改完数据我就用了一下语句,可是运行通不过
Dim mycmd As New SqlCommandBuilder(adapter)
Try
adapter.Update(ds.Tables("users"))
Catch err1 As SqlException
MsgBox(err1.Message)
Catch err2 As Exception
MsgBox(err2.Message)
End Try
它弹出对话框说
dynamic SQL generation for the UpdateCommand is not supported against a selectcommand that does not return any key column information
这是什么意思?
小鸡射手 2004-05-13
  • 打赏
  • 举报
回复
完全同意楼上!

另:
- 访问数据库建议使用Store procedure,不但性能好,而且接口明确
- Microsoft SQLXML可以通过配置将store procedure自动生成web service,如果性能不是问题的话,调用存储过程更为简单:因为web service proxy根据你store procedure的定义自动产生相应类型的参数,而不是SqlParameter中无类型的Value属性
lisiqi 2004-05-13
  • 打赏
  • 举报
回复
试试adapter.update方法。
CMIC 2004-05-13
  • 打赏
  • 举报
回复
微软写了一个数据库操作类Microsoft.ApplicationBlocks.Data,实现了你要的所有功能。
下载地址:http://msdn.microsoft.com/library/en-us/dnbda/html/daab-rm.asp?frame=true
cplusplusman 2004-05-13
  • 打赏
  • 举报
回复
能详细点吗?
thinkingforever 2004-05-13
  • 打赏
  • 举报
回复
用微软的Microsoft.ApplicationBlocks.Data模块

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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