Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

translate to asp/vbscript 2

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
0
0
US
Can someone translate the following asp/jscript to asp/vbsxcript?

Code:
conn = Server.CreateObject("ADODB.Connection");
conn.Open(Application("CONN_STR")="Provider=SQLOLEDB.1;Persist Security Info=False; User ID=uid; Password=pword; Initial catalog=db; Data Source=ip");

inSQL = "INSERT into tbl(field1, field2) VALUES ('"+var1+"','"+var2+"')";
conn.execute(inSQL);

[conehead]
 
set conn = Server.CreateObject("ADODB.Connection")
conn.Open("Provider=SQLOLEDB.1;Persist Security Info=False; User ID=uid; Password=pword; Initial catalog=db; Data Source=ip")

inSQL = "INSERT into tbl(field1, field2) VALUES ('"&var1&"','"&var2&"')"
conn.execute(inSQL)
 
You don't need brackets around method calls unless you use the Call operator.

You don't need semicolons at the end of statements.

Use & instead of + for string concatenation.

Also your call to conn.open is all screwed up, it wont work in either language.

Try this:
Code:
conn = Server.CreateObject("ADODB.Connection")

conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False; User ID=uid; Password=pword; Initial catalog=db; Data Source=ip"

inSQL = "INSERT into tbl(field1, field2) VALUES ('" & var1 & "','" & var2 & "')"

conn.execute inSQL

Or This:
Code:
conn = Server.CreateObject("ADODB.Connection")

conn.Open Application("CONN_STR")

inSQL = "INSERT into tbl(field1, field2) VALUES ('" & var1 & "','" & var2 & "')"

conn.execute inSQL
 
Oh, I missed the most obvious. You need to use SET with objects.


[red]SET[/red] conn = Server.CreateObject("ADODB.Connection")
 
just a thought regarding connections. if this is a database you're going to be calling often, it might be a good idea for you to create a functions page and do an include at the top of your page so you can make the call without having to re-type the connection everytime.

"Where's the Ka-Boom? There's supposed to be an Earth-shattering Ka-Boom!"
Marvin the Martian
 
Or like this if you like to use Call

Code:
set conn = Server.CreateObject("ADODB.Connection")

Call conn.Open(Application("CONN_STR"))

inSQL = "INSERT into tbl(field1, field2) VALUES ('" & var1 & "','" & var2 & "')"

Call conn.execute(inSQL)

This assumes that your Application variable named CONN_STR was already set, if not you've gotta type it out.
 
you can do

conn.Open(Application("CONN_STR"))

without using the call method
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top