Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 update & insert operation, asp, vbscript, Ms Acces
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Dilruba
Starting Member

1 Posts

Posted - 12 November 2007 :  10:48:59  Show Profile
I am using vbscript to insert & update ms accees.

Insert operation is working , but update operation is not working.

I have used the following codes:


connectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\progam files\mail.mdb"






If (CStr(Request("MM_insert")) = "regorg") Then
    
  ConnectionDb = connectionString

  MM_editTable = "Reg"

 MM_fieldsStr  = "username|value|email|value| "

 MM_columnsStr = "username|',none,''|email|',none,''"


  ' create the MM_fields and MM_columns arrays

  MM_fields = Split(MM_fieldsStr, "|")

  MM_columns = Split(MM_columnsStr, "|")


  ' set the form values

  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2

    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))

  Next

  ' append the query string to the redirect URL

  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then

    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then

      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString

    Else

      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString

    End If

  End If

End If




‘ insert & update record


Dim MM_tableValues

Dim MM_dbValues, sql , id

id = Recordset1.Fields.Item("userid").Value

sql = ""


sql="UPDATE customers SET "

If (CStr(Request("MM_insert")) <> "") Then

  MM_tableValues = ""

  MM_dbValues = ""

  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2

    MM_formVal = MM_fields(MM_i+1)

    MM_typeArray = Split(MM_columns(MM_i+1),",")

    MM_delim = MM_typeArray(0)

    If (MM_delim = "none") Then MM_delim = ""

    MM_altVal = MM_typeArray(1)

    If (MM_altVal = "none") Then MM_altVal = ""

    MM_emptyVal = MM_typeArray(2)

    If (MM_emptyVal = "none") Then MM_emptyVal = ""

      If (MM_formVal = "") Then

        MM_formVal = MM_emptyVal

      Else

        If (MM_altVal <> "") Then

          MM_formVal = MM_altVal

        ElseIf (MM_delim = "'") Then  ' escape quotes

          MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"

        Else

          MM_formVal = MM_delim + MM_formVal + MM_delim

        End If

      End If

      If (MM_i <> LBound(MM_fields)) Then

        MM_tableValues = MM_tableValues & ","

        MM_dbValues = MM_dbValues & ","

      End If

      MM_tableValues = MM_tableValues & MM_columns(MM_i)

      MM_dbValues = MM_dbValues & MM_formVal


      sql=sql & "MM_tableValues='" & MM_dbValues & "',"

  Next

   sql=sql & " WHERE userid ='" & id & "'"    



If (Not MM_abortEdit) Then


' insert operation is not creating a problem



  ' execute the insert

    Set MM_editCmd = Server.CreateObject("ADODB.Command")

   MM_editCmd.ActiveConnection = ConnectionDb    

   MM_editCmd.CommandText = MM_editQuery

    MM_editCmd.Execute 

    MM_editCmd.ActiveConnection.Close



update operation is not working



‘ execute the update

Set MM_editCmd = Server.CreateObject("ADODB.Command")

   MM_editCmd.ActiveConnection = MM_editConnection

   MM_editCmd.CommandText = sql

    MM_editCmd.Execute 

    MM_editCmd.ActiveConnection.Close


HuwR
Forum Admin

United Kingdom
20587 Posts

Posted - 12 November 2007 :  10:51:08  Show Profile  Visit HuwR's Homepage
are you getting an error ? if so it would help immensely if you told us what it was.
Go to Top of Page

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 12 November 2007 :  10:54:25  Show Profile  Send pdrg a Yahoo! Message
My god that's a lot of fiddling around - don't tell me, this is wizard-written code?

If the update isn't working, can you add a line as below
‘ execute the update

Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
Response.write (sql) '<--this line here
MM_editCmd.CommandText = sql

This'll render out to the browser what your SQL statement is, so we can see if it's right or wrong. It'd also help to have some clues in which way 'not working' - just fails to update, or comes up with an error message?

:)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000 Version 3.4.07