Datagrids and message boxes!

JamesBowtell

Member
Joined
Feb 26, 2009
Messages
16
Programming Experience
3-5
Hey all!!

I have a datagrid that is bound to one of my tables in my database.

What i would like to do is when i add a row of data and click the save button i want a text box to appear with the following information.

Hey ______ , You have loaned _________ and it is due back on the______



______ being the data that was just saved to the database.

VB.NET:
me.bindingsource1.endedit
me.tableadapter1.update

Messagebox.show(??????????)

is this possible?

cheers
 
You can store the changed information in a DataSet by calling GetChanges() just before you Update.

VB.NET:
		Dim changes As DataSet = Me.TestDataSet.GetChanges()

		Me.Validate()
		Me.MyBindingSource.EndEdit()
		Me.MyTableAdapter.Update(Me.TestDataSet.Suckers)

		With changes.Tables(0).Rows(0)
			MessageBox.Show(String.Format("Hey {0}, You have loaned {1} and it is due back on the {2}", _
			 .Item("FirstName"), _
			 .Item("Amount").ToString("C2"), _
			 .Item("DueDate").ToString("MM/dd/yyyy")))
		End With
 
Cheers for this

I have a problem when running the code,

Object reference not set to an instance of an object.


VB.NET:
      Public Sub saveData()

        Dim changes As DataSet = Me.ITSoftwareLoansSDataSet.GetChanges()

        Me.Validate()

        Me.Tbl_software_loanBindingSource.EndEdit()
        Me.Tbl_software_loanTableAdapter.Update(Me.ITSoftwareLoansSDataSet.tbl_software_loan)


        With changes.Tables(0).Rows(0)
            MessageBox.Show(String.Format("Hey {0}, You have loaned {1} and it is due back on the {2}", _
             .Item("User_ID"), _
             .Item("Date_Loaned").ToString("MM/dd/yyyy"), _
             .Item("Date_ReturnBy").ToString("MM/dd/yyyy")))
        End With


        saveRecord = 0

    End Sub

thanks
 
Object reference not set to an instance of an object.

This is quite possible the most often encountered error message in object oriented programming. Please use Google first, to determine the nature of the problem, the theory of OO programming and why this problem occurs, and how to resolve it
 
I think i have figured it out without google!!

Dragging changes.Tables(0) into the watch window shows that i have no table at index 0.

How would i resolve this?
 
Check that it exists before you try to use it.

I'd have called GetChanges between EndEdit and Update, by the way.. I might also have called it on a datatable, rather than a dataset..
 
I managed to get past the error with the table index by calling getChanges() between .endEdit and .update as suggested by Cjard (code shown below).

VB.NET:
    Public Sub saveData()

        Me.Validate()

        Me.Tbl_software_loanBindingSource.EndEdit()

        Dim changes As DataSet = Me.ITSoftwareLoansSDataSet.GetChanges()

        Me.Tbl_software_loanTableAdapter.Update(Me.ITSoftwareLoansSDataSet.tbl_software_loan)

        With changes.Tables(0).Rows(0)
            MessageBox.Show(String.Format("Hey {0}, You have loaned {1} and it is due back on the {2}", _
             .Item("FirstName"), _
             .Item("Amount").ToString("C2"), _
             .Item("DueDate").ToString("MM/dd/yyyy")))
        End With


    End Sub

the problem i'm having now is that its saying there is no row at index 0. The data is saving to the table, i assumed when a data is saved its row index is set to 0, is that the case or am i way off, any suggestions?

Thanks kindly for your help
 
Very constructive comment.

Could u pass some of your knowledge where I’m going wrong with datagrids and indexes? Could u explain to me how the GetChanges method works with a little example so i can get understand it better!?
 

Latest posts

Back
Top