Inserting data to an access databse

Last post 12-11-2006 4:07 PM by fynne. 1 replies.

Sort Posts:

  • Inserting data to an access databse

    12-10-2006, 6:55 AM
    • Loading...
    • superplum
    • Joined on 05-31-2006, 6:32 PM
    • Posts 5

    I am trying to insert data into a access database when the user clicks a submit button but i get the error:

    Format of the initialization string does not conform to specification starting at index 0.

    This is my code:

    <%@ Import Namespace="System.Data.OleDb" %>
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <script runat=server>
    sub conecter (ByVal sender As Object, ByVal e As EventArgs)
            Dim cmd As New OleDbCommand("INSERT INTO email (email)VALUES('" & TextBox.Text & "')", New OleDbConnection("C:\Documents and Settings\Loowee\My Documents\emails.mdb"))
            cmd.Connection.Open()
            cmd.ExecuteNonQuery()
            cmd.Connection.Close()
        End Sub
    </script>
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            &nbsp; <span style="text-decoration: underline">Quailty mailer v.1<br />
                <br />
                Subscribe:</span> Ener E-mail here: &nbsp;<asp:TextBox ID="TextBox" runat="server"></asp:TextBox>&nbsp;
            <asp:Button ID="Button1" runat="server" Text="Submit" Onclick="conecter"/></div>
        </form>
    </body>
    </html>
    
     

    Can someone please help.

    Filed under: , , ,
  • Re: Inserting data to an access databse

    12-11-2006, 4:07 PM
    Answer
    • Loading...
    • fynne
    • Joined on 12-08-2006, 4:34 PM
    • Posts 29

    I think it's complaining about your connection string.  Here is the one that I use:
    connectionString="Data Source=|DataDirectory|testdb.mdb;Provider=Microsoft.Jet.OLEDB.4.0;"

    where the database is in the App_Data subdirectory.  You could replace the DataDirectory reference with the actual path of your database.

    Also try breaking up the creation of the command and connection into 2 statements.  That will let you know what's dying.

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter