Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


urgent help ..Need a script to insert values into sql databse..

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,64941
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> urgent help ..Need a script to insert values into sql databse..
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 urgent help ..Need a script to insert values into sql d... - 10/9/2008 6:58:22 AM   
  yspkiran

 

Posts: 3
Score: 0
Joined: 10/9/2008
Status: offline
hi every one ...my name is kiran..i am new to this forums...i need urgent help.... i am doing a project related to sqldatabase.. i need to read the values wich are scanned by the Netstumbler software and write the values into a table in sql database..i tried a lot but it is not working..here is the code i am working with...


public d
public p
d=0

sub OnScanResult (SSID,BSSID,CapFlags,Signal,Noise,LastSeen)
dim fso, fl, ts,Rs
Dim objConnection,objRecordset,strSearchCriteria

set fso = CreateObject("Scripting.FileSystemObject")

on error resume next
if d=1 then

   set conn = server.createobject("ADODB.Connection")
   conn.connectionstring = "Provider=SQLOLEDB;Data source=UT142503\SQLEXPRESS; initial catalog=testbed;"
 
If conn.State=1 Then

Msgbox "Connected"

else

Msgbox "Not Connected"

End If


conn.Open connectionstring
     'New Contact Name
     strSQL = "INSERT INTO testbed.dbo.buffer (d_value, macid) VALUES ( '" & d &" ' , ' " & BSSID & " ' )"
     conn.Execute strSQL
     Response.Write "Data written to database!"
     Msgbox "Data written to database"
     conn.Close

End If

If strSQL.State=1 Then
Msgbox "Connected"
else
Msgbox "Not Connected"
End If
End Sub


sub OnScanComplete (FoundNew,SeenBefore,LostCOntact,BestSNR)
d=d+1
End Sub






I need to write the values of variable ' d ' and the values for BSSID given by the Netstumbler software into table called "buffer"  in database.the sript is executing without any errors but the values are not written into the table. I cannot see any values in the table. I tried the sript for creating a excel file and exporting the values from software to excel. and then written a stored procedure to load the values to table.. it is working...but i need the script for directly connecting to database and writing the values to table....the sript for excel file is....



public d
public p
d=0

sub OnScanResult (SSID,BSSID,CapFlags,Signal,Noise,LastSeen)
dim fso, fl, ts
set fso = CreateObject("Scripting.FileSystemObject")
on error resume next
   if d=1 then

   set ts = fso.OpenTextFile("c:\ap.xls", 2, True)


   else

   set ts = fso.OpenTextFile("c:\ap.xls", 8, false)
   end if
ts.write(d)
ts.write("    ")
ts.Write(BSSID)
ts.write("    ")
ts.Write(Signal+100)
ts.write("    ")
ts.WriteLine(Noise)
ts.Close()
End Sub


sub OnScanComplete (FoundNew,SeenBefore,LostCOntact,BestSNR)
d=d+1
End Sub


sub onDisableScan()
msgbox(d)
d=1
End sub



plz help me as soon as possible i am waiting for your valuable suggestions..... Thank you very much for your hits...but i need ur valuable suggestions...
 
 
Post #: 1
 
 RE: urgent help ..Need a script to insert values into s... - 10/9/2008 12:24:45 PM   
  fosterr_2000

 

Posts: 115
Score: 0
Joined: 12/18/2004
From:
Status: offline
I like to use the Microsoft SQL Server provider to connect to SQL.  Here is a sample using a SQL account.


  Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Open "Driver={SQL Server};" & _
                     "Server=UT142503\SQLEXPRESS;" & _
                     "Database=testbed;" & _
                     "user id=someuser;" & _
                     "password=yourpassword;"
  Set objRSSQL = CreateObject("ADODB.Recordset")
  strSQL = "INSERT INTO testbed.dbo.buffer (d_value, macid) VALUES ( '" & d &" ' , ' " & BSSID & " ' )"
  objRSSQL.Open strSQL, objConnection


or using a trusted account like so:

  Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Open "Driver={SQL Server};" & _
                     "Server=UT142503\SQLEXPRESS;" & _
                     "Database=testbed;" & _
                     "Trusted_Connection=yes;"
  Set objRSSQL = CreateObject("ADODB.Recordset")
  strSQL = "INSERT INTO testbed.dbo.buffer (d_value, macid) VALUES ( '" & d &" ' , ' " & BSSID & " ' )"
  objRSSQL.Open strSQL, objConnection


Keep in mind that I have not tested this so their could be some syntax errors, but maybe it will point you in the right direction.

Hope this helps.

(in reply to yspkiran)
 
 
Post #: 2
 
 RE: urgent help ..Need a script to insert values into s... - 10/9/2008 12:51:43 PM   
  yspkiran

 

Posts: 3
Score: 0
Joined: 10/9/2008
Status: offline
hi...thanks for your reply....i am using microsoft sql server database and it requires windows authentication for logging....but i dont know about the provider.. is it OLEDB or Sql server...

Can you plz post the script for my requirements.....i hope u help me..

(in reply to fosterr_2000)
 
 
Post #: 3
 
 RE: urgent help ..Need a script to insert values into s... - 10/9/2008 1:24:41 PM   
  fosterr_2000

 

Posts: 115
Score: 0
Joined: 12/18/2004
From:
Status: offline
Either provider will work.  They are just different ways / drivers that can be used to connect.

I am not sure about the rest of your script but maybe this will be close.  I am not sure why you are passing 6 vars into your sub and only using one of them?

If this doesn't work please post the full script.

public d
public p
d=0
sub OnScanResult (SSID,BSSID,CapFlags,Signal,Noise,LastSeen)
on error resume next
if d=1 then
  Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Open "Driver={SQL Server};" & _
                     "Server=UT142503\SQLEXPRESS;" & _
                     "Database=testbed;" & _
                     "Trusted_Connection=yes;"
  Set objRSSQL = CreateObject("ADODB.Recordset")
  strSQL = "INSERT INTO testbed.dbo.buffer (d_value, macid) VALUES ('" & d & "', '" & BSSID & "')"
  objRSSQL.Open strSQL, objConnection
  Response.Write "Data written to database!"
  Msgbox "Data written to database"
End If

sub OnScanComplete (FoundNew,SeenBefore,LostCOntact,BestSNR)
d=d+1
End Sub

Hope this helps.

(in reply to yspkiran)
 
 
Post #: 4
 
 RE: urgent help ..Need a script to insert values into s... - 10/9/2008 2:47:59 PM   
  yspkiran

 

Posts: 3
Score: 0
Joined: 10/9/2008
Status: offline
hi Fosterr..........Thanks a lots of tons......the code is working.....it is writing the data into table dude.......Thank you very much for you help.....

(in reply to fosterr_2000)
 
 
Post #: 5
 
 RE: urgent help ..Need a script to insert values into s... - 10/10/2008 7:01:23 AM   
  fosterr_2000

 

Posts: 115
Score: 0
Joined: 12/18/2004
From:
Status: offline
Glad I could help.  I'll send you my bill.

Just kidding.

(in reply to yspkiran)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> urgent help ..Need a script to insert values into sql databse.. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts