Question:
What is the syntax for having a C# document in Visual studio to get it to connect with a Access database?
2010-06-02 07:10:53 UTC
Trying to get my Visual studio document to update an access database when I type my name into the text box field. I am having difficulty getting what I enter into the database. If anyone can assist that would be great.
Three answers:
2010-06-02 08:12:49 UTC
You should start using LINQ rather than the old techniques. LINQ is far superior and provides a lot more flexibility. You can see guides on using it:



http://msdn.microsoft.com/en-us/library/bb397926.aspx

http://msdn.microsoft.com/en-us/library/bb397980.aspx
Billion Dollar Boy
2010-06-02 07:24:11 UTC
I do a lot of coding in VB.net. Although it may be slightly different, VB and C# are very similar.



In VB.net, you need to create a connection string to the Access database, and that would change depending on whether it was a .mdb, .accdb, or adp version of MS Access.



If you are using MS Access 2007, which is .accdb format, this would be the VB.net connection and sql command sample:





Dim Fullpath As String = "C:\path_to_your_access_database\"

Dim DatabasePath As String = Fullpath & "nameOfYourDatabase.accdb"





Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DatabasePath)



Dim StrFill As String = "INSERT INTO YourTableName (fieldname1) VALUES ('" & textbox1.text & "')"







cn.Open()

cmd = New OleDbCommand(StrFill, cn)

sqlcount = cmd.ExecuteNonQuery

cn.Close()
l_town_51
2010-06-02 09:56:19 UTC
http://www.csharphelp.com/2006/01/ms-access-application-with-c/



http://www.c-sharpcorner.com/UploadFile/mimrantaj/Database102102008130743PM/Database1.aspx


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...