|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Saving Data Into An SQL Server Database
Hi everyone,
I'm a newbie in VB programming. I'm currently developing a relatively simple program: 1. to extract data from an an antivirus scanning activity log file (get the last scan results) located in every PC 2. to save all these info to an SQL Server database. I used the File System Object (TextStream) in VB to read data from the log file (text file). That proved to be successful. (Refer to the attachment) Trouble is, I cannot seem to save this info (last scan results) into the database. I'm using the ADO Data Control in VB for this purpose. What should I do? And what datatype in the SQL Server should I set for the scan results (refer to the attachment - with an average of 11 lines)? Should the datatype be 'text'? Any help at all is greatly appreciated. Thankies! Code: '----To save the data into the database---- Private Sub cmdSubmit_Click() adoVirusScanLog.Recordset.Fields("ScanResult") = Text1.Text adoVirusScanLog.Recordset.Fields("ScanDate") = Text2.Text adoVirusScanLog.Recordset.Update End Sub '----To view the last scan results---- Private Sub cmdView_Click() adoVirusScanLog.Recordset.AddNew '----Set textbox Text2 to contain the value of the current date, '----to be saved into the database. '----Textbox Text2 have proper data source and data field values '----from the data control. Text2.Text = txtDate.Text '----To read last scan results from the activity log file into textbox txtScan---- Dim txtStream As TextStream, s As String Dim pos1, pos2 As Long 'Get the text log file for reading Set txtStream = mFso.GetFile("C:\My Documents\VSCLog.txt").OpenAsTextStream(ForReading) pos1 = 0 txtScan.Text = "" 'Read until the first occurence of the current date Do s = txtStream.ReadLine pos1 = InStr(1, s, dateString) 'dateString of type String contains the current date Loop Until pos1 <> 0 'Read until the first occurence of "Scan Summary" Do s = txtStream.ReadLine pos2 = InStr(1, s, "Scan Summary") Loop Until pos2 <> 0 'Print the line of the first occurence of "Scan Summary" txtScan.Text = txtScan.Text & s & vbNewLine 'Print the rest of the line for "Scan Summary" Do s = txtStream.ReadLine txtScan.Text = txtScan.Text & s & vbNewLine Loop While (txtStream.AtEndOfStream = False) '----Finished reading the last scan results---- Call txtStream.Close '----Set textbox Text1 to contain the last scan results from textbox txtScan, '----to be saved into the database. '----Textbox Text1 have proper data source and data field values '----from the data control. Text1.Text = txtScan.Text End Sub '----Form Load---- Private Sub Form_Load() txtDate.Text = Date dateString = txtDate.Text End Sub |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Saving Data Into An SQL Server Database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|