Home > Software engineering >  Using vb to upload files to the data, can upload only one cannot point once again prompt error
Using vb to upload files to the data, can upload only one cannot point once again prompt error

Time:11-02

 Dim cn As ADODB. Connection 
Dim the rs As the ADODB library you
Dim mstream As ADODB. Stream

Private Sub Form_Load ()
Set the cn=New ADODB. Connection
Set the rs=New ADODB. You
The Set mstream=New ADODB. Stream
End Sub
Private Sub cmdSaveFile_Click ()
Cn. Open "the Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Initial Catalog=saveFile; The Data Source=PCOS - 05071342
"Rs. Open the "select * from TestPpt", cn, 1, 3
Mstream. Type=adTypeBinary

SQL="select filename from testppt where filename like FilePPT. The filename"
If the rs. RecordCount & gt;=1 Then
MsgBox "you want to upload the contents of the existing", vbOKCancel + 32, "tip"
End the If
Mstream. LoadFromFile "\ test. The PPT"


Rs. AddNew
Rs. The Fields (" Filecontents ")=mstream. Read
Rs! FileName=FilePPT. FileName

Rs. Update

Rs. Close

End Sub

Tip: objects do not allow the operation when it is open,
And also don't tip when you upload the same file name

CodePudding user response:

Connection to repeat open, of course not

CodePudding user response:

 if cn. State<> Adstateclosed then cn. Close 
Cn. Open "the Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Initial Catalog=saveFile; The Data Source=PCOS - 05071342
"If the rs. State<> Adstateclosed then rs. Close
Rs. Open the "select * from TestPpt", cn, 1, 3
  • Related