|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Write to SQL via vbscript
Can anyone give me the code to write to a SQL table from a vbscript. I have a script running on all my PC's which write to a flat file which I then import. Can I just run the script and have it write directly to SQL.
|
|
#2
|
||||
|
||||
|
What SQL engine are we talking about here? Access, SQL Server, MySQL, Oracle or what? Also, it would help if you specified what you are writing to the text files currently.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
|
#3
|
|||
|
|||
|
U can modify a asp file realize this function to vbs file..
|
|
#4
|
|||
|
|||
|
Hi!
Here os the code I use for writing data into DB (it calls stored procedure for checking inserted data, hope it will be usefull for you) <code> Function LogResultSQL (strSQLServer, strDBName, strProcName, strUser, strPassword, strScriptName, strCompName, dtDateTime, strEventID, strEventDesc, strEventExecCommand, numEventResult) ' ' Call stored procedure strProcName stored in database strDBName on SQL Server strSQLServer, authenticating as user strUser with password strPassword ' Insert parameters for strProcName are: strScriptname, strCompName, dtDateTime, strEventID, strEventDesc, strEventExecCommand a numEventResult ' Function returns the return code of that stored procedure ' Dim objConnection Dim objCmd Dim objParams Dim numReturnValue Set objConnection = CreateObject("ADODB.Connection") objConnection.Open "Provider=sqloledb;Data Source=" & strSQLServer & ";Initial Catalog=" & strDBNAme & ";User Id=" & strUser & ";Password=" & strPassword & ";" Set objCmd = CreateObject("ADODB.Command") Set objCmd.ActiveConnection = objConnection objCmd.CommandText = strProcName objCmd.CommandType = 4 Set objParams = CreateObject("ADODB.Parameter") objParams.Type = 3 ' adInteger objParams.Direction = 4 'adParamReturnValue objCmd.Parameters.Append objParams Set objParams = CreateObject("ADODB.Parameter") objParams.Type = 200 ' adVarChar objParams.Size = 50 objParams.Direction = 1 'adParamInput objParams.Value = strCompName objCmd.Parameters.Append objParams Set objParams = CreateObject("ADODB.Parameter") objParams.Type = 135 ' adDBTimeStamp objParams.Direction = 1 'adParamInput objParams.Value = dtDateTime objCmd.Parameters.Append objParams Set objParams = CreateObject("ADODB.Parameter") objParams.Type = 200 ' adVarChar objParams.Size = 1000 objParams.Direction = 1 'adParamInput objParams.Value = strEventID objCmd.Parameters.Append objParams Set objParams = CreateObject("ADODB.Parameter") objParams.Type = 200 ' adVarChar objParams.Size = 4000 objParams.Direction = 1 'adParamInput objParams.Value = strEventDesc objCmd.Parameters.Append objParams Set objParams = CreateObject("ADODB.Parameter") objParams.Type = 200 ' adVarChar objParams.Size = 1000 objParams.Direction = 1 'adParamInput objParams.Value = strEventExecCommand objCmd.Parameters.Append objParams Set objParams = CreateObject("ADODB.Parameter") objParams.Type = 3 ' adInteger objParams.Direction = 1 'adParamInput objParams.Value = numEventResult objCmd.Parameters.Append objParams Set objParams = CreateObject("ADODB.Parameter") objParams.Type = 200 ' adVarChar objParams.Size = 1000 objParams.Direction = 1 'adParamInput objParams.Value = strScriptName objCmd.Parameters.Append objParams objCmd.Execute 'Set objParams = objCmd.Parameters.Item(0) Set objParams = objCmd.Parameters(0) numReturnValue = objParams.Value Set objConnection = Nothing Set objCmd = Nothing Set objParams = Nothing LogResultSQL = numReturnValue end Function ' LogResultSQL (strSQLServer, strDBName, strProcName, strUser, strPassword, strCompName, dtDateTime, strEventID, strEventDesc, strEventExecCommand, numEventResult) </code> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Write to SQL via vbscript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|