开发者

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

开发者 https://www.devze.com 2023-04-12 08:43 出处:网络
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 Stud开发者_StackOverflow社区io 2010, Windows 7 x64, Office 2010 x86 (but I alre

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 Stud开发者_StackOverflow社区io 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?


You need to use SQL parameters.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号