Rodrigo Souza
Rodrigo Souza

Reputation: 7352

Connecting ASP.NET with Access database 2010 using windows 7 x64

I'm trying to use a database I have in Access 2010 and trying to connect it using ASP.NET. Currently, I'm using Visual Studio 2010, Windows 7 x64, Office 2010 x86 (but I already tried with Office 2010 x64) and using OleDb. I was told that it isn't that easy if you have a x64 system because of the data provider.

I already tried a lot of connection strings for this code snippet:

Protected Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
    Dim DBPath As String = "C:\Users\Rodrigo\Documents\Database1.accdb"
    Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & ";Persist Security Info=False;")
    Dim cmd As New OleDbCommand
    With cmd
        .CommandText = "insert into Users (nome) values (" & Me.txtNome.Text & ")"
        .Connection = cn
        .Connection.Open()
        .ExecuteNonQuery()
        .Connection.Close()
        .Dispose()
    End With
    cn.Dispose()
End Sub

The farthest I could get was with the Microsoft.ACE.OLEDB.12.0 provider which generated an error on .ExecuteNonQuery(), saying that it needs some arguments.

What would be the correct way to insert data in my access database using ASP.NET given my settings?

Upvotes: 0

Views: 2175

Answers (1)

SLaks
SLaks

Reputation: 888077

You need to use SQL parameters.

You're inserting an unquoted string into your SQL, resulting in invalid SQL.

Upvotes: 1

Related Questions