用 CommandBuilder.GetUpdateCommand()方法自动获得 更新的 SQL语句,前提是你的表必须要有主键但我可以确保我的表有\且只有一个主键, 为什么调用这条语句为出现
"沒有傳回任何索引鍵資料行資訊的 SelectCommand 不支援 UpdateCommand 的動態 SQL 產生"
这样的错误!如果我将表名更换为另一个表, 则可以正常得到. (我仔细比较这两个表, 没有发现不一样的地方都是有一个主键)
"沒有傳回任何索引鍵資料行資訊的 SelectCommand 不支援 UpdateCommand 的動態 SQL 產生"
这样的错误!如果我将表名更换为另一个表, 则可以正常得到. (我仔细比较这两个表, 没有发现不一样的地方都是有一个主键)
解决方案 »
- 网页上怎样弹出一个窗体????
- asp.net开发都需要什么技术???
- 当文本框获得焦点的时候弹出一个日期控件(急!在线等)
- 怎样通过URL读取出网站里面的内容?
- ASP.NET中如何读取EXCEL的值?并存进数据库
- Asp.net里面用C#,有没有类似confirm这样的函数控制流程。
- 再线求救:中途退出程序要用什么语句??
- 【请教】为什么百度爬虫请求UTF-8网站的网站URL里的中文参数是乱码?
- 写了一个发邮件的程序怎么出错误了
- 问一下菜的问题,在DREAMWEAVER MX中新建一个HTML基本网页,在插入菜单中为什么表格是虚的,不可选?
- 散分!!高兴啊!!好不容易,升到4个裤叉叉!!高兴!!哈哈哈哈哈哈!
- 如何使用资源
Dim cnn As SqlConnection
Dim sqldataset As DataSet
Dim sqlc As SqlCommand
Dim sqla As SqlDataAdapter
Dim sqlb As SqlCommandBuilder cnn = New SqlConnection
sqldataset = New DataSet
cnn.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString") selectstr = "SELECT timetext FROM timetab"
sqlc = New SqlCommand(selectstr, cnn)
sqla = New SqlDataAdapter sqla.SelectCommand = sqlc
sqlb = New SqlCommandBuilder(sqla)
sqla.Fill(sqldataset) sqldataset.Tables(0).Rows(0).Delete()
sqla.Update(sqldataset)
我用的是 Oracle 数据库, 所以用的是 OleDbDataAdapter
打开表格用的是 "Select * from AdjustH"
查阅: OleDbDataAdapter.SelectCommand.CommandText也是"Select * from AdjustH"
可以肯定AdjustH表中有一个主键, 但还是出错如果打开表格时将 AdjustH 换成 "Select * from Supy", 则一切正常
因为我把所有数据库的操作全部封装在一个类中, 所以代码很多, 不好贴TO: cuike519(marshal(修练中...))
AdjustH的确和其它的表有关联, 但我上表面提到的 Supy表也是有关联的
The following limitations apply to automatic command generation.Unrelated Tables Only
The automatic command generation logic generates INSERT, UPDATE, or DELETE statements for standalone tables without taking into account any relationships to other tables at the data source. As a result you may encounter a failure when calling Update to submit changes for a column that participates in a foreign key constraint in the database. To avoid this exception, do not use the CommandBuilder for updating columns involved in a foreign key constraint and instead, explicitly specify the statements used to perform the operation.Table and Column Names
Automatic command generation logic fails if column names or table names contain any special characters, such as spaces, periods, quotation s, or other nonalphanumeric characters, even if delimited by brackets. Fully qualified table names in the form of catalog.schema.table are supported.
执行到 GetUpdateCommand();就产生异常了, 所以得不到值
TO: cuike519(marshal(修练中...))
刚才仔细检查了一下:
AdjustH表 没有 外键
AdjustB表 有三个外键
Supy表 有三个外键结果: AdjustH, AdjustB异常
Supy通过而且: 根据 MSDN的解释,
As a result you may encounter a failure when calling Update to submit changes for a column that participates in a foreign key constraint in the database.
如果数据表有外键, 那也只是在 执行 Update()更新时才会捕获导常, 不是像我这样
GetUpdateCommand()时就产生异常