Tag: INSERT
MSSQL Search & Add Query Using Vbscript
by Installer on Feb.23, 2010, under MSSql Query
With This VBScript you can search into a field for Value and add it (if you want).
If you use the following script you Dont need to open ”SQL Server Managment Studio”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | Do Searchdata = InputBox("Please enter the Value", "Input") Loop Until Searchdata = "" cnstring = "Provider=SQLOLEDB.1;Password=PASSWORD;Persist Security Info=True;User ID=USERNAME;Initial Catalog=USERNAME;Data Source=192.168.2.2;" cmdtext = "SELECT * FROM DATABASE where FIELD_NAME = "& Searchdata &"" Set cn = CreateObject("adodb.connection") Set cmd = CreateObject("adodb.command") cn.connectionstring = cnstring cn.Open cmd.activeconnection = cn cmd.commandtext = cmdtext Set rs = CreateObject("adodb.recordset") rs.cursortype = 3 rs.locktype = 3 rs.Open(cmd) While Not rs.EOF And Not rs.BOF 'WScript.Echo rs.Fields.Item("FIELD_NAME").Value Data = rs.Fields.Item("FIELD_NAME").Value 'WScript.Echo Data rs.MoveNext Wend rs.Close cn.Close If Data = "" Then WScript.Echo "Ta Dedomena den Yparxoun sti Vasi" answer=MsgBox ("Do you want to Add the "& Data &" ", 36, "ADD THE VALUE ") If answer = 6 Then cnstring = "Provider=SQLOLEDB.1;Password=PASSWORD;Persist Security Info=True;User ID=USERNAME;Initial Catalog=USERNAME;Data Source=192.168.2.2;" cmdtext = "INSERT INTO DATABASE (FIELD_NAME) VALUES (" & Data & ")" Set cn = CreateObject("adodb.connection") Set cmd = CreateObject("adodb.command") cn.connectionstring = cnstring cn.Open cmd.activeconnection = cn cmd.commandtext = cmdtext cmd.Execute cn.Close WScript.Quit Else WScript.echo "NO" WScript.Quit End If Else WScript.Echo "Ta Dedomena Yparxoun Sti Vasi" End If |