I have the following code which assigns values to a datarow and and adds to the datatable. I want to write function which returns a datarow which enables me to write less code. Please check the code below and provide me any suggestions
objRow = dtTODO.NewRow
objRow.Item("Item") = "Test"
objRow.Item("Message") = "Test"
objRow.Item("ButtonText") = "Add"
dtTODO.Rows.Add(objRow)
objRow = dtTODO.NewRow
objRow.Item("Item") = "Test2"
objRow.Item("Message") = "Test2"
objRow.Item("ButtonText") = "Add"
dtTODO.Rows.Add(objRow)
Assume that I am adding the above records. I want to create a function which returns a datarow as,
Public Function ItemRow(ByVal strItem As String, ByVal strMessage As String, ByVal strButtonText As String, ByVal strUrl As String) As DataRow
End Function
And add this as,
dtTODO.Rows.Add(ItemRow(item, msg,bttext,url))
Hope I am not confusing too much :).
You function signature seems ok only You have to pass the dtTODO.Newrow reference to the function as well.
Try this:
You can get much better code as well.
Please convert the above code to VB