Print Page | Close Window

Inserting Records

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=7175
Printed Date: 29 March 2026 at 10:55pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Inserting Records
Posted By: IrishNewbie
Subject: Inserting Records
Date Posted: 11 November 2003 at 5:09pm

Guys,

This piece of code to insert a new student into the DB was working perfectly, i dont know hwat i did to screw it up but maybe the error is blatantly obvious to someone more experienced.

<%@ Page Language="VB" Debug="True" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    Sub btnInsertClick(Sender As Object, E As EventArgs)

         Dim aConnection As OleDbConnection = New OleDbConnection
         Dim aConnectionString As String
         Dim aQuery As String
         aConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Inetpub\wwwroot\records.mdb"
         aConnection.ConnectionString = aConnectionString
         Dim aCommand As OleDbCommand = New OleDbCommand
         aConnection.Open()
         aQuery = "Insert Into Students(StudentID, FirstName, LastName, EmailName, BirthDate, Pword) VALUES ('"& StudID.Text &"', '"& F_Name.Text &"', '"& L_Name.Text &"', '"& Email.Text &"', '"& D_O_B.Text &"', '"& Pword1.Text &"')"
         aCommand.Connection = aConnection
         aCommand = New OleDbCommand(aQuery, aConnection)
        
    End Sub

</script>
<html>
<head>
</head>
<body background="./images/graduate.gif">
    <form runat="server">
        <div align="center">
             <table width="607" align="center" border="0">
                 <tbody>
                     <tr>
                           <td colspan="3" height="201">
                               <img height="91" src="images/crest.gif" width="574" align="top" border="3" />
                               <table cellspacing="0" cellpadding="0" width="100%" border="0">
                                   <tbody>
                                         <tr>
                                             <td height="80">
                                                  <h2 align="center"><font face="geneva,arial" size=+3><b>Registration Information </b></font>
                                                  </h2>
                                                  <font face="geneva,arial" size="-1">&nbsp; </font></td>
                                         </tr>
                                   </tbody>
                               </table>
                           </td>
                     </tr>
                     <tr>
                           <td align="right" width="198">
                               <font face="Arial" size="2">First Name: </font></td>
                           <td width="399">
                               <asp:TextBox id="F_Name" runat="server" width="200px" maxlength="25"></asp:TextBox>
                               <asp:RequiredFieldValidator id="FNameReq" runat="server" ErrorMessage="* You Must Enter a First name" ControlToValidate="F_Name"></asp:RequiredFieldValidato r>
                           </td>
                     </tr>
                     <tr>
                           <td align="right">
                               <font face="Arial" size="2">Last Name:</font>
                           </td&g




Replies:
Posted By: MorningZ
Date Posted: 11 November 2003 at 5:13pm

are we supposed to guess what "isn't working perfectly" is?

do you get an error message?



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: MorningZ
Date Posted: 11 November 2003 at 5:15pm

also.. no where do you actually execute the command

aCommand.ExecuteNonQuery()

after the "New Command" line



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: IrishNewbie
Date Posted: 11 November 2003 at 5:16pm
No error message, just when i click the submit button the password fileds clear and usually after i did that it was entered but now it doesnt enter it. Is it a problem with where i have my DB?? All my files are in the wwwroot folder and i have my DB there as well.


Posted By: MorningZ
Date Posted: 11 November 2003 at 5:19pm
let me know how it turns out after you add the line you are missing

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: IrishNewbie
Date Posted: 11 November 2003 at 5:23pm

System.Data.OleDb.OleDbException: Operation must use an updateable query.

this is the error i get when i put in that line, i took it out cos it was causing this error earlier, what exactly does the line do???



Posted By: MorningZ
Date Posted: 11 November 2003 at 5:43pm

omg.. you cannot be serious?

a line causes an error and you just "take it out" to try to fix it?  lol.. you got some issues ahead if thats your method of solving problems.....

that line i post is what actually runs the query you are presenting the database... your code w/o it never says "do it"

and that "updatable query" error message (as i believe this is in borgs tutorials section) means that the database is in a directory which the web server doesn't have the proper permissions... which it sure in hell shouldn't since your database is sitting in the root of your web application (easily the WORST place for a database to exist)....

you gots some readin' to do... starting http://www.webwiz.net/asp/faq/access_database_faq.asp#FAQ1 - with here  and that PM i sent you



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 12 November 2003 at 8:24am

You could make the sub actually handle something. I don't see where you call the sub when the button is clicked, but that could be me, since I just ran quickly trough it.

EDIT: Alright! I've seen it. But using the Handles.Button might be better.

My solution is easy. Build it again! Sometimes I screw up to, and rebuilding the thing from scratch is the best solution.



-------------
Gone..


Posted By: IrishNewbie
Date Posted: 12 November 2003 at 9:14am

ok i found what was wrong, i needed to add /mycomputer/ASPNET onto the user list and give it full control.

thanks



Posted By: Diep-Vriezer
Date Posted: 12 November 2003 at 9:16am
If it worked before, and you hadn't done this yet, how come it worked before then?

-------------
Gone..


Posted By: IrishNewbie
Date Posted: 12 November 2003 at 2:22pm
I think i removed it when i was going through a tutorial of how to fix the problem of permissions.  When i unchecked the inheritance option they all were removed bar one.


Posted By: MorningZ
Date Posted: 12 November 2003 at 2:30pm

hopefully you didn't give that permission to the root directory of the website.....

that's just asking for an amateur hacker to delete your site



-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net