Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Updating SQL table

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Updating SQL table
  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 >>
 Updating SQL table - 7/9/2007 12:49:31 AM   
  Abs777

 

Posts: 5
Score: 0
Joined: 7/5/2007
Status: offline
I want to update some info in a table How do I run a sqlquery using VBscript to update the info?  I can connect fine but I can't get the table to update.  I am using this query but I am getting errors.

UPDATE documents
set edit = 0
where doc_nbr = 6

Thanks for any help!
 
 
Post #: 1
 
 RE: Updating SQL table - 7/9/2007 2:45:10 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
What are you using as your connection to your SQL database?

Show what you have and we can help with any adjustments / additions.

(in reply to Abs777)
 
 
Post #: 2
 
 RE: Updating SQL table - 7/9/2007 4:15:35 AM   
  Abs777

 

Posts: 5
Score: 0
Joined: 7/5/2007
Status: offline
Thank you!

Dim cnt
Set cnt = CreateObject("ADODB.Connection")
cnt.Provider = "SQLOLEDB"
cnt.ConnectionString= "Driver={SQL Server};Server=(local);Database=Apex_db;UID=sa;PWD="
cnt.Open

(in reply to Country73)
 
 
Post #: 3
 
 RE: Updating SQL table - 7/9/2007 7:04:08 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
This should get you started on "Updating" in SQL; just replace the items in bold red type to your information.

DIM cnt
SET cnt = CREATEOBJECT("ADODB.Connection")
cnt.Provider = "SQLOLEDB"
cnt.ConnectionString= "Driver={SQL Server};Server=(local);Database=Apex_db;UID=sa;PWD="
cnt.Open
   sql = "UPDATE <Table> SET "
   sql = sql & "<Column1 Name>='" & Column1.value & "',"
   sql = sql & "
<Column2 Name>='" & Column2.value & "',"
   sql = sql & "
<Column3 Name>='" & Column3.value & "'"
cnt.Execute sql
cnt.Close

(in reply to Abs777)
 
 
Post #: 4
 
 RE: Updating SQL table - 7/9/2007 11:24:49 PM   
  Abs777

 

Posts: 5
Score: 0
Joined: 7/5/2007
Status: offline
I get all the way to the

CNT.Execute sql

and I get this error


String or Binary Data would be truncated.

Any ideas???

(in reply to Country73)
 
 
Post #: 5
 
 RE: Updating SQL table - 7/10/2007 1:17:01 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Try running this with only one update line.

cnt.Open
sql = "UPDATE <Table> Set "
sql = sql & "<Column1 Name>=" & Column1.value & ""
cnt.Execute sql
cnt.Close


If that still doesn't work, you may want to ECHO the string you are trying to update to make sure it looks correctly.
One of the most common mistakes is the spacing / running words together.

(in reply to Abs777)
 
 
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 >> Updating SQL table 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