What Is The Best Way To Confirm DataBase Enteries

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
hey Guys, what is the best 'Method' of confirming database stuff.

VB.NET:
 Public Function Car_Paid(reg As String) As Boolean
        Connection.Open()
        Dim CARcommand As New OleDb.OleDbCommand("UPDATE cars SET Paid = true WHERE (Reg = @Reg)", Connection)
        CARcommand.Parameters.AddWithValue("@Reg", reg)
        CARcommand.ExecuteNonQuery()

        Dim ODRCommand As New OleDb.OleDbCommand("SELECT Count(*) From OrderNumbers WHERE (Reg = @Reg)", Connection)
        ODRCommand.Parameters.AddWithValue("@Reg", reg)

        If CInt(ODRCommand.ExecuteScalar) > 0 Then
            ODRCommand = New OleDb.OleDbCommand("UPDATE OrderNumbers SET Paid = True WHERE (Reg = @Reg)", Connection)
            ODRCommand.Parameters.Clear()
            ODRCommand.Parameters.AddWithValue("@Reg", reg)
            ODRCommand.ExecuteNonQuery()
        End If

        Dim WDCommand = New OleDb.OleDbCommand("SELECT Count(*) From WorkDone WHERE Reg = @Reg", Connection)
        WDCommand.Parameters.AddWithValue("@Reg", reg)

        If CInt(WDCommand.ExecuteScalar) > 0 Then
            WDCommand = New OleDb.OleDbCommand("UPDATE WorkDone SET Paid = True WHERE  (Reg = @Reg)", Connection)
            WDCommand.Parameters.AddWithValue("@Reg", reg)
            WorkDone_da.UpdateCommand.ExecuteNonQuery()
        End If
        
        Connection.Close()
        Return True
    End Function

I was thinking of making a small form that would, display the rows edited, added,updated and so on.

purly on the off chance something gets 'Paid' that shouldn't get paid.

im not sure if i can use a data grid view as the data is going to be diffrent.

can anyone give me some suggestions?

and il try and fiure out the code myself (hopefully)

thanks guys
 
Sorry, i might have over complicated the question, il basic is out a bit

the Code windows is some code il be using to mark items as paid.

so i am looking to Execute the code above and then Show the user what has just been done, IE display the rows that where updated from unpaid to paid. but this is going to be Multiple rows From Multiple tables

The type of answer im steering towards is, in my thread you told me that Executescalar wasn't 'how it's Done' for checking if rows exists, The 'Way To Do It' was the check the count of the rows return.

What Would be the PROPER way to display the rows that have been updated.

in real world use, the user is going to Select an 'Invoice Row' from a data grid

i hope this is clearer if not,... il think harder :D

thanks again

The Help Is SOO helpful and i am VERY grateful for it
 
Hi,

The only thing that you can return from a Database about what has been Updated/Inserted/Deleted is the "Number of Rows that Have been affected" by assigning the ExecuteNonQuery method of a Command to a Variable, so I think you are on the wrong track here.

So, why not have a Form/Control or whatever you want, that displays the rows that are ABOUT to be updated, which the User then has to press a "Confirm" Button before those updates are committed to the Database. This could easily be achieved by using Select queries on your Tables with the same Where clause as your Update queries and displaying this original information first before committing your updates to the Database.

Hope that helps.

Cheers,

Ian
 
hi Ian thanks for your input, yea i like your thinking on that one, the way my search works and the way the user is going to mark things of as paid, the form needs to be closed and open again to get the new information.

The only thing is, is their a control i can use to display data rows, as far as i know a datagrid view can only display rows from 1 table at a time.

i would rather be able to show all the rows at once instead of having to display 4 possbly 5 datagridviews :D

if their isn't a componant that can do it, then il just use datagridviews ..

sorry just had a thought il not delete the above as its still an option , can i use something like 'Windows Explorer' the way it would display folders in a parent child kinda of view like below.
because the data is in a parent child structure as such invoice>Car>Order number>Work done
Untitled.png
 
Hi,

The TreeView control is what you are looking for. Just construct the Parent and Child nodes of the TreeView in the same manner as the Parent Child relationship of your DataTables.

Hope that helps.

Cheers,

Ian
 
Back
Top