Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hy,

Sorry for the poor english...

I was wondering what the best practice for handling data on a winform is.
I would like to use an access database because of the easy and open end at the database reporting side.

True , there is a lot of google stuff available on that topic.

And i tried a great deal of possibilities, butt without a satisfing result.
I had my hope up on LINQ but i searched 6 houres on how to linq with a variable column name for filtering purpose... i found little or nothing on that so i let it be.

I also use the hard coding way with ADO.net as seen bellow. But it is frustrating that when u make a mistake in the sql expression that it still runs and u can loose quite a long time searching for the solution.

I also used the ado.net tableadapters as seen bellow, and like described on msdn .com but when i use the update functionality nothing happens in my db.
-> Yes i have a primary key in my table...

I would appreciate some guidance and experiances...

Thanks in advance, best regards.

Mathias

What I have tried:

- LINQ
- ADO.net hard coding
- TABLEADAPTERS

VB
Try
            Dim strSQLUPDATE As String = "UPDATE " & strTABEL & " SET NAAM = @NAAM ,POSTCODE = @POSTCODE, STRAAT = @ADRES, NR = @NR, STAD = @STAD, LAND = @LAND, TEL = @TEL, BTWPLICHTIG = @BTWPLICHTIG, BTWNR = @BTWNR, EMAIL = @EMAIL WHERE KLANTID = @KLANTID"

            Dim dbCONNECTION As New OleDbConnection(My.Settings.PRORENTConnectionString)

            Dim dbCOMMANDUPDATE As New OleDbCommand(strSQLUPDATE, dbCONNECTION)

            dbCONNECTION.Open()

            dbCOMMANDUPDATE.Parameters.AddWithValue("@NAAM", NAAM)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@POSTCODE", POSTCODE)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@ADRES", ADRES)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@NR", NR)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@STAD", STAD)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@LAND", LAND)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@TEL", TEL)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@BTWPLICHTING", BTWPLICHTING)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@BTWNR", BTWNR)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@EMAIL", EMAIL)
            dbCOMMANDUPDATE.Parameters.AddWithValue("@KLANTID", CustomerId)

            dbCOMMANDUPDATE.ExecuteNonQuery()

            dbCONNECTION.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


___________ this is the tableadpter update code

VB
Try 
    Me.Validate()
    Me.CustomersBindingSource.EndEdit()
    Me.CustomersTableAdapter.Update(Me.NorthwindDataSet.Customers)
    MsgBox("Update successful")

Catch ex As Exception
    MsgBox("Update failed")
End Try
Posted
Updated 8-Mar-16 19:24pm
v2
Comments
dan!sh 9-Mar-16 1:30am    
You can make use of stored procedures this CP article if it supports your access version and standard ADO.net code if you wish. Best choice would however depend on your comfort and what is best for your need.
Maciej Los 9-Mar-16 2:01am    
Stored procedures aren't available in MS Access database, but we can play with some queries as with stored procedures.
dan!sh 9-Mar-16 2:44am    
My bad. Didn't really noticed it is access.
Maciej Los 9-Mar-16 3:17am    
Don't worry...
Cheers,
Maciej

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900