Help please! Creating record in ASP for SQL Server!
Help please! Creating record in ASP for SQL Server!
Author
Discussion

Nic Jones

Original Poster:

7,190 posts

251 months

Friday 19th October 2007
quotequote all
Right all i'm a bit stuck.

I've got a database table in SQL Server 2005 called "migrate" under the database name "NIC_TEST" and I need to create a simple web form with just name and email address to write to the database using the "Addnew" method in ASP (not .Net as i've not learnt that yet)

My problem is, I just cannot get it to work, and most websites I look at for help are writing to Access which is not much help!

Can anyone on here write me a basic script (I can understand it when I read it) that would make this work please as i've now spent the last 4 hours tearing my hair out doing battle with it!

Thanks!

m12_nathan

5,138 posts

290 months

Friday 19th October 2007
quotequote all
Exactly the same as access but with a different connection string.

Nic Jones

Original Poster:

7,190 posts

251 months

Friday 19th October 2007
quotequote all
I'm sure I tried that and it didn't work! frown

It's so bloody annoying spending hours on end trying to hunt out a scripting problem!

m12_nathan

5,138 posts

290 months

Friday 19th October 2007
quotequote all
There are about a million examples of adding a record to a database using vbscript on google...

http://www.stardeveloper.com/articles/display.html...

What is your connection string btw? does your sql work ok in query analyser when connecting with the same credentials?

Don

28,378 posts

315 months

Friday 19th October 2007
quotequote all
Nic Jones said:
I'm sure I tried that and it didn't work! frown

It's so bloody annoying spending hours on end trying to hunt out a scripting problem!
It will work.

You need an Application variable with a DSN in it.

Application("DSN&quotwink = "Driver=SQL Server;SERVER=SERVERNAME;DATABASE=DATABASENAME;UID=sa;PWD="

Then you can simply open a recordset

Set rs = Server.CreateObject("ADODB.Recordset&quotwink
rs.Open sql,Application("DSN&quotwink,adoOpenForwardOnly,adoLockReadOnly,adoCmdText or whatever.


BTW. NEVER use AddNew or "clever" recordsets. All too often they fail to work or aren't portable across databases or whatever. Just use good old fashioned "SnapShot" type recordsets to read data. If you want to insert something build a SQL INSERT statement and execute it

sql = "INSERT INTO MYTABLE(MYFIELD) VALUES (" & strValue & &quotwink

Set conn = Server.CreateObject("ADODB.Connection&quotwink
conn.Open Application("DSN&quotwink

conn.Execute sql