Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2014
    Posts
    151
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Connecting to MS database in ASP.NET

    Hello

    I have a couple of debug errors in my aspx.vb code (Visual Studio 2013), but wondered if the basic structure of what I have is correct to connect to a database. I am basically trying to insert form data (username, password, email) into my database:

    Code:
    Imports Microsoft.AspNet.Identity
    Imports Microsoft.AspNet.Identity.EntityFramework
    Imports Microsoft.AspNet.Identity.Owin
    Imports System
    Imports System.Linq
    Imports System.Web
    Imports System.Web.UI
    Imports System.Data.OleDb
    
    Partial Class Account_Register
        Inherits System.Web.UI.Page
    
    <configuration>
    <connectionStrings><add name="usersConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\myDatabase.mdb" providerName="System.Data.OleDb"/>
    </connectionStrings>
     <system.web>
       <compilation debug="true" targetFramework="4.0"/>
    
        Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Using conn As New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("usersConnectionString").ConnectionString)
                Dim Sql As String = "INSERT INTO userlist (username,password, strEmail) VALUES (@username,@password, @strEmail)"
                Dim cmd As New OleDbCommand(Sql, conn)
                conn.Open()
                cmd.Parameters.AddWithValue("@username", username.Text)
                cmd.Parameters.AddWithValue("@password", password.Text)
                cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)
                cmd.ExecuteNonQuery()
                conn.Close()
            End Using
        End Sub
    
        </system.web>
    </configuration>
    
    End Class
    Thanks for any advice.

    Blue

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,763
    Thanks
    41
    Thanked 191 Times in 190 Posts
    seems correct at first glance. what are the errors?

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

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