Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
hi
I write back SQL server database when using odbc,but not working.why?please help me!
Is there something that I am missing on configuration/settings?
Here is my macro below:
sub writerecords
dim conn,sqlstr
set conn=CreateObject("ADODB.Connection") '创建连接对象
conn.ConnectionString ="DSN=sql1" '
conn.open 'not working???????
set table=ActiveDocument.GetSheetObject("TB01")
CellRect=ActiveDocument.GetApplication().GetEmptyRect()
CellRect.Top=0
CellRect.Left=0
CellRect.Width=table.GetColumnCount
CellRect.Height=table.GetRowCount
set CellMatrix=table.GetCells(CellRect)
for RowIter=CellRect.Top+1 to CellRect.Height-1
zhibao=CellMatrix(RowIter)(0).Text
xiaxiang=CellMatrix(RowIter)(1).Text
shangxiang=CellMatrix(RowIter)(2).Text
sqlstr="insert into tab1(ID,Name,Age) values('"&zhibao&"','"&xiaxiang&"','"&shangxiang&"')"
conn.execute sqlstr
next
conn.close
set conn=nothing
msgbox "写入成功!"
end sub
Hi,
Is the DSN configured to allow read and write operations? Make sure in the "Data Sources (ODBC)" tool that the driver you are using has the permissions correctly.
Apart from that, verify that the user specified in the DSN has permissions to write in the tables.
miguel