Adding a row to a database with SQL

Results 1 to 4 of 4

Thread: Adding a row to a database with SQL

  1. #1
    Join Date
    Dec 1969
    Posts
    206

    Default Adding a row to a database with SQL

    I was wondering how to add a new row to a database. I know how to write to a database using SQL to select specified rows, the problem is I don&#039t know how to write a new row. Any help would be appreciated.<BR><BR>Brandon

  2. #2
    Join Date
    Dec 1969
    Posts
    5

    Default RE: Adding a row to a database with SQL

    sorry I can&#039t help with your problem - but you said you know how to write to a database. I have tried loads od different code <BR>can you point me in the direction of a use full tutorial or give me some tips - <BR><BR>many thanks<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    206

    Default RE: Adding a row to a database with SQL

    Here is the code I use. You have to include the top file, and you have to be able to select rows in the database using the sql statement. All the dim statements are to just get my variable from the page before. This script changes the database and then sends them back to a page. <BR><BR>The best tutorial I have found is on the site www.asp-help.com, at http://asp-help.aspin.com/index/default.asp?tree=aspin/tutorial/database<BR><BR>This has it all basically.<BR><BR>Brandon<BR><BR><BR>&#060;!-- #INCLUDE FILE="adovbs.inc" //--&#062;<BR>&#060;%<BR>Dim pass<BR>pass=CStr(Request("password"))<BR>Dim user<BR>user=CStr(Request("username"))<BR>Dim header<BR>header=CStr(Request("headers"))<BR>Dim calender<BR>calender=CStr(Request("calender"))<BR> Dim text1<BR>corkboard=CStr(Request("corkboard"))<BR>D im reminder<BR>reminder=CStr(Request("reminder"))<BR> Dim image1<BR>image1=CStr(Request("image1"))<BR>Dim greeting<BR>greeting=CStr(Request("greeting"))<BR> Dim race<BR>race=CStr(Request("race"))<BR><BR><BR>Dim Connect, ChangeRS, Query<BR>Set Connect = Server.CreateObject("ADODB.Connection")<BR>Connect .Open "mystanley"<BR><BR>Set ChangeRS = Server.CreateObject("ADODB.Recordset")<BR>Query = "SELECT * FROM mystanley WHERE username=&#039"&user&"&#039 and password=&#039"&pass&"&#039"<BR>ChangeRS.Open Query, Connect, adOpenStatic, adLockOptimistic<BR><BR>%&#062;<BR>&#060;% ChangeRS("header") = header<BR>ChangeRS("calender") = calender<BR>ChangeRS("corkboard") = corkboard<BR>ChangeRS("reminders") = reminder<BR>ChangeRS("image1") = image1<BR>ChangeRS("race") = race<BR>ChangeRS.Update<BR>%&#062;<BR>&#060;% Response.buffer = True <BR>Response.Cookies("greeting") = greeting<BR>%&#062;<BR>&#060;% response.redirect("validated.asp?password="&pass&" &username="&user&"") %&#062;

  4. #4
    Join Date
    Dec 1969
    Posts
    41

    Default RE: Adding a row to a database with SQL

    You can use the "INSERT INTO" statement:<BR>INSERT INTO tbl (stringField1, numField1) VALUES(&#039hello&#039, 2)<BR><BR>OR, even easier<BR>with an open recordset do this:<BR><BR>oRs.addnew<BR>oRs("stringField1") = "hello"<BR>oRs("numField1") = 2<BR>oRs.update


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •