Private Sub CommandButton1_Click ()
On Error GoTo err
Dim Cur_connect As New ADODB. Connection
Dim Cur_cmd As New ADODB.Com mand
Dim Cur_record As New ADODB. You
Dim Star_col As Integer
Dim Star_row As Integer
Dim Cur_row As Integer
Dim Cur_Col As Integer
Dim Cur_count As Integer
Dim Cur_str As String
Dim Pre_cell, Cur_cell As String
If MsgBox (" sure you want to upload work log?" , vbOKCancel, "confirmation")=vbCancel Then
The Exit Sub
End the If
ActiveSheet. Cells. The Font. ColorIndex=0
Cur_connect. The ConnectionString=ThisWorkbook. The ConnectionString
Cur_connect. Open
Cur_cmd. ActiveConnection=Cur_connect
Cur_record. ActiveConnection=Cur_connect
'Cur_record. Open the "select * from PG_AREA where pA_INPUTNO='" & amp; Sheet2. Cells (1, 2) & amp; "'
"'If Not Cur_record. EOF Then
'Cur_record. Close
'Set Cur_record=Nothing
'Set Cur_cmd=Nothing
'Cur_connect. Close
'Set Cur_connect=Nothing
'Exit Sub
'End If
Star_col=2
Star_row=3
Cur_count=0
Cur_connect. BeginTrans
While Not (Cells (Star_row, Star_col)="")
Pre_cell=Cells (Star_col Star_row - 1, + 1)
Cur_cell=Cells (Star_row, Star_col + 1)
If Cur_cell & lt;> Pre_cell Then
'Cur_record. Open the "select * from PG_AREA where pa_code='" & amp; Sheet1. Cells (Star_row Star_col) & amp; "'
"'If Cur_record. EOF Then
Cur_str="insert into ceshi. GZRZ (XM, GW, SB, SM, DJSC, XX, QT, SCRQ, GZJY) values ('" & amp; Cells (Star_row Star_col) & amp; "', '" & amp; Cells (Star_row, Star_col + 1) & amp; "', '" & amp; Cells (Star_row, Star_col + 2) & amp; "', '" & amp; Cells (Star_row, Star_col + 3) & amp; "', '" & amp; Cells (Star_row Star_col + 4) & amp; "', '" & amp; Cells (Star_row Star_col + 5) & amp; "', '" & amp; Cells (Star_row, Star_col + 6) & amp; "', '" & amp; Cells (Star_row Star_col + 7) & amp; "', '" & amp; Cells (Star_row, Star_col + 8) & amp; "')
"Cur_cmd.Com mandText=Cur_str
Cur_cmd. Execute
Cur_count=Cur_count + 1
'End If
'Cur_record. Close
End the If
Star_row=Star_row + 1
Wend
Cur_connect.Com mitTrans
MsgBox (" working log upload (" & amp; Cur_count & amp; Article ") ")
Cur_connect. Close
The Set Cur_connect=Nothing
The Exit Sub
Err:
MsgBox "import data exception:" & amp; Err. The Description
Rows (Star_row). The Font. ColorIndex=3
Cur_connect. RollbackTrans
Cur_connect. Close
The Set Cur_connect=Nothing
End Sub
ThisWorkbook code below
Public the ConnectionString As String
Private Sub Workbook_Open ()
The ConnectionString="Provider=MSDAORA. 1; Password=tg123456; User ID=GTFG; Data Source=fg8; Persist Security Info=True "
End Sub
Private Sub Workbook_SheetActivate (ByVal Sh As Object)
The ConnectionString="Provider=MSDAORA. 1; Password=ceshi; User ID=ceshi. Data Source=ceshi; Persist Security Info=True "
End Sub
CodePudding user response:
Even no reasons, are generally the ConnectionString problem, you can use the ADO Data control to try to connect, and then use it to generate the connection string to set up your own ConnectionString, (I usually do so)CodePudding user response: