explaination of this code

seprienna

New member
Joined
Feb 1, 2007
Messages
4
Programming Experience
Beginner
explanation of this code

problem been resolved
 
Last edited:
'an event handler header
Private Sub DeleteCustomerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteCustomerToolStripMenuItem.Click

'a boolean variable delaration
Dim errormessage As Boolean = False

'try some code that might fail
Try

'remove the current row from DatView. I would have used DatView.CurrentRow.Remove
DatView.Rows.Remove(DatView.CurrentRow)

'send changes in the first table of dtst back to the database
adptr.Update(dtst.Tables(0))

'start of error handling block
Catch ex As Exception

'show a message
MessageBox.Show("Delete was not successful")

'set a boolean variable
errormessage = True

'end of failing code block
End Try

'pointless thing here. should put the bold bit in the Try block, above the word Catch
If errormessage = False Then MessageBox.Show("Successful deleted")

'end of the subroutine
End Sub

Quote:
'start of an event handler sub
Private Sub AddNewCustomerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewCustomerToolStripMenuItem.Click

'create a new form
Dim addcustomersForm As New frmaddcust

'show it modally
addcustomersForm.ShowDialog()

'dispose of it (not necessary)
addcustomersForm.Dispose()

'call the retrievecustomers function, discard any result
RetrieveCustomers()

'end of the subroutine
End Sub
 
thanks you so much for your details explanation.:)

If you don't mind,can you explain to me what does the following code means?
i've an exam next week, but i don't understand most of the code given by my lecturer.
your help is greatly appreciated.thanks
 
Last edited:
'method(sub/function) header
Private Sub RetrieveCustomers()

'initialise the conn variable with a new OleDbConnection object, connection details found in strConn (a connection string)
conn = New OleDbConnection(strConn)

'initialise dtview with a new dataview object
dtview = New DataView

'initialise dtst witha new dataset object
dtst = New DataSet

'initialise adptr with a new oledbdataadapter, giving it an sql and telling it which connection to use
adptr = New OleDbDataAdapter(strSQL, conn)

'initilaise cmndbld with a new comamndbuilder object - usually used to automatically generate insert, update and delete queries from a select statement
commbuild = New OleDbCommandBuilder(adptr)

'use the adapter to fill a datatable called "customers", within the dtst datset
adptr.Fill(dtst, "Customers")

'assign the table property of the dtview to be the customers datatable we just filled
dtview.Table = dtst.Tables("Customers")

'assign the datasource of DatView to be the dataview
DatView.DataSource = dtview

'end of method
End Sub
 
thanks you so much.
i'm learning a lot from you.
anyway, do you have any recommended site where i can go through my revision on ADO.net?
 
note, because i dont generally do people's homework for them, and these could just as easily be homework as exam prep, youll need to have a go at explaining any future codes yourself and I will correct your attempt - this is the last that i will do 100%

if you were expected to do this in an exam, my comments are examples of what might be expected as answers. pay attention to detail - if a property is being set, then say its a property, say its name and waht it is being set to..

if you are asked what the code does, then saying "uses the oledb data access library to fill a datatable called customers and show it, via a dataview, in a (?grid) called datview" would be a reasonable answer
 
note on the revision issue, you dont appear to be doing things in the way i would expect for .net 2.0 - we dont do the low level stuff directly any more, so any website i point you to wont tell you things related to what you want to know...

thats not to say that youre learning it wrong.. just make sure that you learn the modern way after they finish teaching you the clumsy low level hard work way :D
 
note, because i dont generally do people's homework for them, and these could just as easily be homework as exam prep, youll need to have a go at explaining any future codes yourself and I will correct your attempt - this is the last that i will do 100%
no worries, i understand most of it by now. By the way, that was my own coding, i did it myself but unfortunately i don't really know what does some of the code means. all i know was that i need to include it in the program to make it works(thats what i been told)

if you were expected to do this in an exam, my comments are examples of what might be expected as answers. pay attention to detail - if a property is being set, then say its a property, say its name and waht it is being set to..
i get the picture on how to explain most of the other codes i made myself.thanks again for your kind help.
 
Back
Top