VB连接好oracle数据库后添加记录为何报错

来源:百度知道 编辑:UC知道 时间:2024/06/19 10:27:37
连接好oracle数据库后添加记录为何报错:实时错误'91',对象变量或With块变量未设置,报错语句为".AddNew"

Adodc1.ConnectionString = "MSDAORA.1;User ID=apps;Data Source=ebs3;Persist Security Info=False"
Adodc1.RecordSource = "KLCUSTOM_BOMS"
Adodc1.Refresh
With Adodc1.Recordset
.AddNew
.Fields(0) = ex.Cells(k, 1)
.Fields(1) = ex.Cells(k, 2)
.Fields(2) = ex.Cells(k, 3)
.Fields(3) = ex.Cells(k, 4)
.Fields(4) = ex.Cells(k, 5)
.Fields(5) = ex.Cells(k, 6)
.Update
End With
没有啦,我把with语句去掉,全部加上Adodc1.Recordset 也不行,还是AddNew那里报错,难道是oracle数据库不能用AddNew命令?
知道怎么回事了,语法没有错误,而且数据库连接测试也是成功,我用DataGrid1,可以读出这张表的内容,但是却添加不了记录,难道是oracle数据库有限制,不可以添加数据,或是oracle添加记录不是AddNew命令?

你的变量K在那里?另外是不是有自动编号的字段?oracle数据库不太熟,但是SQL语句应该是一样的。
ex.Cells(k, 1) 等数据来源是否准确,字段类型是否统一?

Adodc1.ConnectionString = "MSDAORA.1;User ID=apps;Data Source=ebs3;Persist Security Info=False"
Adodc1.RecordSource = "KLCUSTOM_BOMS"
Adodc1.Refresh
if Adodc1.Recordset.bof and Adodc1.Recordset.eof then
else
With Adodc1.Recordset
.AddNew
.Fields(0) = ex.Cells(k, 1)
.Fields(1) = ex.Cells(k, 2)
.Fields(2) = ex.Cells(k, 3)
.Fields(3) = ex.Cells(k, 4)
.Fields(4) = ex.Cells(k, 5)
.Fields(5) = ex.Cells(k, 6)
.Update
End With
end if

是不是with和end with语句那少空格