Solved

asp.net database upate

Posted on 2002-03-12
6
406 Views
Last Modified: 2007-12-19
why does thjis code not do anything at all. it comes back saying all is in the database but the database has not been touched:


<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<style type="text/css">
a{color:#0000ff;font-family:verdana;text-decoration:none;}
a:hover{font-family:verdana;text-decoration:underline overline;}
</style>

<script runat="server">
 function ExecuteStatement(strSQL)
      dim objCmd as new OleDbCommand(strSQL, Conn)
     
      try
         objCmd.Connection.Open()
         objCmd.ExecuteNonQuery()
      catch ex as Exception
       
      end try
     
      objCmd.Connection.Close()
   end function




 sub Page_Load(obj as Object, e as EventArgs)
loginas.text=request("who")
 
 end sub


'declare connection
   dim Conn as new OleDbConnection( _
      "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\commweb\cgi-bin\sabre.mdb")
 
   sub Submit(obj as object, e as eventargs)
    if accounttype.selecteditem.text="Credit Account" then
 acnumvalid.enabled="True"
 else
 acnumvalid.enabled="False"
 end if
   
   if ad.checked then
   address1valid.enabled="True"
address2valid.enabled="True"
pcodevalid.enabled="True"
   else
address1valid.enabled="False"
address2valid.enabled="False"
pcodevalid.enabled="False"
end if
   
      if page.isvalid then
        
      dim i, j as integer
      dim strText as string
      dim blnGo as boolean = true
       
     
     
      dim strSQL as string = "INSERT INTO members " & _
         "(company, turnover, address1, address2, address3, county, pcode, employees, www, notes, email, fax, tel, accountowner, country, a, bywho, accounttype ) VALUES (" & _
         "'" & company.text & "'," & _
         "'" & turnover.text & "'," & _
         "'" & address1.text & "'," & _
         "'" & address2.text & "'," & _
         "'" & address3.text & "'," & _
         "'" & county.text & "'," & _
             "'" & pcode.text & "'," & _
          "'" & employees.text & "'," & _
          "'" & www.text & "'," & _
            "'" & notes.text & "'," & _
            "'" & email.text & "'," & _
            "'" & fax.text & "'," & _
            "'" & tel.text & "'," & _
            "'" & acown.selecteditem.text & "'," & _
            "'" & country.text & "'," & _
            "'" & acnum.text & "'," & _
                        "'" & loginas.text & "'," & _
            "'" & accounttype.selecteditem.text & "')"
                  
      ExecuteStatement(strSQL)
     response.write (("<br><br><font face=arial size=2><a href='addmem.aspx?who=") & request("who") & ("'>Add another record?</a><br><br>Please select an option on the left menu otherwise"))
        response.end
    end if
   end sub
   
   
   
   

   
 
dim num=0

   

 

 
        Sub btReset_OnClick(Sender As Object, E As EventArgs)

            company.Text= ""
            turnover.text=""
            address1.text=""
            address2.text=""
            address3.text=""
            county.text=""
            tel.text=""
            fax.text=""
            www.text=""
            notes.text=""
            employees.text=""
            acnum.text=""
            pcode.text=""
            email.text=""
            country.text=""
            
            
      End Sub
 

 

   </script>
        


 
<html><body>

 
   <form runat="server">
     <asp:validationsummary runat="server" displaymode="bulletlist"/>
   <asp:Label id="lblMessage" runat="server"/>
    <asp:Label id="count" runat="server"/>  
      <asp:Panel id="AddPanel" runat="server">
       

            <table>

<tr>
       <td>Company Name:</td>
       <td><asp:TextBox id="company" runat="server"/>
         <asp:requiredfieldvalidator runat="server"
         controltovalidate="company"
         errormessage="You must enter a Company Name!"
         display="dynamic"/>
         </td>
</tr>
<tr>
       <td>Account Type:</td>
       <td><asp:listbox autopostback="true" ontextchanged="test" id="accounttype" runat="server" size=1>
         <asp:listitem value="Nothing" >* Please Select *</asp:listitem>
         <asp:listitem>Credit Account</asp:listitem>
         <asp:listitem>Credit Card</asp:listitem>
         <asp:listitem>Diners Lodge Account</asp:listitem>
      
         </asp:listbox>
         <asp:comparevalidator runat="server"
         controltovalidate="accounttype"
         type="string"
         operator="notequal"
         valuetocompare="Nothing"
         errormessage="You must select Account Type"
         />
        </td>
</tr>

<%if request("accounttype")="Credit Account" then

%>
<tr>
       <td>Account Number:</td>
       <td><asp:TextBox id="acnum" runat="server"/>
         <asp:requiredfieldvalidator id="acnumvalid" runat="server"
         controltovalidate="acnum"
         errormessage="You must enter an account number!"
         display="dynamic"/>
         </td>
</tr>
<%end if%>



      <tr>
       <td></td>
       <td><asp:checkbox   id="ad" text="Address?" autopostback runat="server" /></td>
</tr>
      <%
if ad.checked then
%>
<tr>
       <td>Address:</td>
        
       <td><asp:TextBox id="address1" runat="server"/>
         <asp:requiredfieldvalidator id="address1valid" runat="server"
         controltovalidate="address1"
         errormessage="You must enter a street name!"
         display="dynamic"/>
         </td>
</tr>

<tr>
       <td></td>
       <td><asp:TextBox id="address2" runat="server"/>
         <asp:requiredfieldvalidator id="address2valid" runat="server"
         controltovalidate="address2"
         errormessage="You must enter a location!"
         display="dynamic"/></td>
</tr>
<tr>
       <td></td>
       <td><asp:TextBox id="address3" runat="server"/></td>
</tr>
<tr>
       <td>County:</td>
       <td><asp:TextBox id="county" runat="server"/></td>
</tr>
<tr>
       <td>Post Code:</td>
       <td><asp:TextBox id="pcode" runat="server"/>
         <asp:requiredfieldvalidator id="pcodevalid" runat="server"
         controltovalidate="pcode"
         errormessage="You must enter a Post Code!"
         display="dynamic"/>
         </td>
</tr>
<tr>
       <td>Country:</td>
       <td><asp:TextBox id="country" runat="server"/></td>
</tr>
<%end if%>
<tr>
       <td>Telephone:</td>
       <td><asp:TextBox id="tel" runat="server"/>
           <asp:regularexpressionvalidator
         runat="server"
         controltovalidate="tel"
         validationexpression="\d{5,15}"
         errormessage="That is not a valid Telephone Number" />
         </td>
</tr>
<tr>
       <td>Fax:</td>
       <td><asp:TextBox id="fax" runat="server"/>
          <asp:regularexpressionvalidator
         runat="server"
         controltovalidate="fax"
         validationexpression="\d{5,15}"
         errormessage="That is not a valid Fax Number" />
         </td>
</tr>
<tr>
       <td>E-mail:</td>
       <td><asp:TextBox id="email" runat="server"/>
         <asp:regularexpressionvalidator
         runat="server"
         controltovalidate="email"
         validationexpression="^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
         errormessage="That is not a valid E-mail Address"
         /></td>
</tr>
<tr>
       <td>Www:</td>
       <td><asp:TextBox id="www" runat="server" value="http://"/></td>
</tr>
<tr>
       <td>Notes</td>
       <td><asp:TextBox id="notes" hidden="true" textmode="multiline" rows="3" runat="server"/></td>
</tr>
<tr>
       <td>Account Owner</td>
       <td><asp:listbox  id="acown" runat="server" size=1>
         <asp:listitem value="Nothing" >* Please Select *</asp:listitem>
         <asp:listitem>Business House 1</asp:listitem>
         <asp:listitem>Business House 2</asp:listitem>
         <asp:listitem>Business House 1 - ND</asp:listitem>
         <asp:listitem>Serco</asp:listitem>
         <asp:listitem>Hamersmith Hospital</asp:listitem>
         <asp:listitem>Mirror</asp:listitem>
         <asp:listitem>E1</asp:listitem>
         <asp:listitem>New Accounts</asp:listitem>
         <asp:listitem value="conf">Conferences</asp:listitem>
         </asp:listbox>
         <asp:comparevalidator runat="server"
         controltovalidate="acown"
         type="string"
         operator="notequal"
         valuetocompare="Nothing"
         errormessage="You must select Account Owner"
         />
         </td>
        
      
</tr>
<tr>
       <td>Employees(Approx):</td>
       <td><asp:TextBox id="employees" runat="server"/></td>
</tr>
<tr>
       <td>Turnover (2001):</td>
       <td><asp:TextBox id="turnover" runat="server"/></td>
</tr>
</table>

       <asp:Button id="btSubmit" runat="server"
                  text="Add"
                  OnClick="Submit" />
            <asp:Button id="btreset" runat="server"
                  text="Clear"
                  OnClick="btReset_onclick" />
      </asp:Panel>
           <br><br><font face=arial size=1>Entry will be saved against:<asp:Label id="loginas" runat="server"/>
   </form>
</body></html>
<!--#include file="bottom.asp"-->
0
Comment
Question by:bolox
6 Comments
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 6856638
Put something to show the error state inside the catch section of the "try...catch...end" statement in the ExecuteStatement function. There can be errors in your query, but you won't see them, as you catch the sql error and ignores it...
0
 
LVL 1

Author Comment

by:bolox
ID: 6856779
what would you suggest? is there a default

 "catch everything"

??

B
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 6857057
every exception class in .NET framework is derived from Exception base class. So any time you are unsure of what exception to catch, handle the egeneric Exception.

try
{
}
catch (Exception ex)
{
  Trace.Write(ex.Message);
}

In your case, you can handle SqlException.

.NET framework does not return error codes back the way Win32 APIs used. Now it throws exceptions. So you should always put the code in try/catch handlers. All .NET APIs describe what kind of exceptions may be throws for all the respective calls.

Naveen
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 29

Accepted Solution

by:
Göran Andersson earned 2 total points
ID: 6860405
This should at least give you an error message if there is an error:

try
    objCmd.Connection.Open()
    objCmd.ExecuteNonQuery()
catch ex as Exception
    Response.Write "ADO error:<br>" & ex.Message
    Response.End
end try

You can build something nicer later on...
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7017320
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20274034.html
http://www.experts-exchange.com/questions/Q.20275804.html
http://www.experts-exchange.com/questions/Q.20275780.html
http://www.experts-exchange.com/questions/Q.20243407.html
http://www.experts-exchange.com/questions/Q.20240541.html
http://www.experts-exchange.com/questions/Q.20294935.html
http://www.experts-exchange.com/questions/Q.20297880.html
http://www.experts-exchange.com/questions/Q.20298256.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Author Comment

by:bolox
ID: 7020947
sorry foir the delay in getting back to you
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now