首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB中使用adodb更新excel中内容遇到的有关问题

2012-09-23 
VB中使用adodb更新excel中内容遇到的问题Dim excelConn1 As New ADODB.ConnectionexcelConn.ConnectionStr

VB中使用adodb更新excel中内容遇到的问题
Dim excelConn1 As New ADODB.Connection

excelConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Mode=ReadWrite;Data Source=" & excelFile & ";Extended Properties=""Excel 12.0 Xml;HDR=No;IMEX=1;"""

excelConn.Open

Dim excelRec As ADODB.Recordset

excelRec.Open "select * from [01公共设施$]", excelConn, 1, 3

excelRec(21) = “new” 这里出错提示"不能更新。数据库或对象为只读。"

excelRec.Update

应该是哪里是只读的,但是我找不到在哪儿改,看了个帖子在连接字中加"ReadOnly=False;" 我加了就报错


[解决办法]
和你分享一下源码,有需要订做软件的话叫我

VB code
Private Sub Form_Load()Dim RS As ADODB.RecordsetSet RS = GetExcelRs(App.Path & "\book1.xls")MsgBox RS.RecordCountMsgBox RS(0)RS(0) = TimerRS.UpdateRS.CloseEnd Sub'┏〓〓〓〓〓〓〓〓〓 GetExcelRs,start 〓〓〓〓〓〓〓〓〓┓'[简介]:'VB读取EXCEL工作薄某个表中数据Function GetExcelRs(ByVal sFile As String, Optional ExcelSheetName As String = "sheet1", Optional ErrInfo As String) As ADODB.Recordset   '[mycode_id:2025],edittime:2011-9-7 下午 02:15:41   On Error GoTo Err   Dim RS As ADODB.Recordset   Set RS = New ADODB.Recordset   Dim ConnStr As String   ConnStr = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile & ";ReadOnly=False"      RS.Open "SELECT * FROM [" & ExcelSheetName & "$]", ConnStr, 1, 3      Set GetExcelRs = RS   Set RS = Nothing      Exit Function   Err:   ErrInfo = Err.Description   MsgBox ErrInfoEnd Function'┗〓〓〓〓〓〓〓〓〓  GetExcelRs,end  〓〓〓〓〓〓〓〓〓┛
[解决办法]
IMEX=1
改为
IMEX=2就可以了

IMEX=0:写
IMEX=1:读
IMEX=2:读写

热点排行