Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 16th, 2005, 03:37 AM
dt_aiying dt_aiying is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 93 dt_aiying User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 58 m 8 sec
Reputation Power: 4
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
Attached Files
File Type: txt Sample Last Scan results.txt (684 Bytes, 76 views)

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Saving Data Into An SQL Server Database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT