 |
BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7
 | This is the forum to discuss the Wrox book Beginning Microsoft Visual Basic 2008 by Thearon Willis, Bryan Newsome; ISBN: 9780470191347 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 28th, 2009, 08:01 AM
|
|
Registered User
|
|
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Databindings
I have applied your binding techniiques with my database for managing assets and it seems to work perfectly in most of my controls except one of date where a get a error arising from DBNull value (where there is a null value in a date column). How can I first check for a DBNull value on a Dataview before databinding. Is there any one who can show me how to go about it. Following is my code:
Code:
Private Sub cmdSearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearchButton.Click
Try
Dim dsAssPart As New DataSet
Dim SelectedId As Integer
If AssetIDComboBox.SelectedValue IsNot Nothing Then
SelectedId = DirectCast(AssetIDComboBox.SelectedValue, Integer)
End If
Using Cnn As New SqlConnection("Data Source=DELEBYS-785804M;Initial Catalog=ASSETS MANAGER_beSQL1;" & _
"Integrated Security=True")
cmd = New SqlCommand
cmd.Connection = Cnn
cmd.CommandText = "AssetParticularsByID_sp"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@AssetID", SelectedId)
objDataAdapter = New SqlDataAdapter(cmd)
objDataAdapter.Fill(dsAssPart, "AssetParticulars")
End Using
objDataView = _
New DataView(dsAssPart.Tables("AssetParticulars"))
ClearBindings()
RestoreDataBindins()
Sub ClearBindings()
AssetIDTextBox.DataBindings.Clear()
FPAUAssetNoTextBox.DataBindings.Clear()
DateReceivedDateTimePicker.DataBindings.Clear()
AssetDescriptionTextBox.DataBindings.Clear()
ModelTextBox.DataBindings.Clear()
SerialNumberTextBox.DataBindings.Clear()
ConditionAtAcquisitionTextBox.DataBindings.Clear()
DateCurrentLocDateTimePicker.DataBindings.Clear()
PurchasePriceTextBox.DataBindings.Clear()
SalvageValueTextBox.DataBindings.Clear()
StatusIDTextBox.DataBindings.Clear()
DateWrittenoffDateTimePicker.DataBindings.Clear()
DateBoardedOffDateTimePicker.DataBindings.Clear()
DeletedOnDateTimePicker.DataBindings.Clear()
AssetNameComboBox.DataBindings.Clear()
AllocateAtComboBox.DataBindings.Clear()
OfficeListComboBox.DataBindings.Clear()
EmployeeComboBox.DataBindings.Clear()
ProcuredAtComboBox.DataBindings.Clear()
DonorNameComboBox.DataBindings.Clear()
End Sub
Sub RestoreDataBindins()
AssetIDTextBox.DataBindings.Add("Text", objDataView, "AssetID")
FPAUAssetNoTextBox.DataBindings.Add("Text", objDataView, "FPAUAssetNo")
DateReceivedDateTimePicker.DataBindings.Add("Value", objDataView, "DateReceived")
AssetDescriptionTextBox.DataBindings.Add("Text", objDataView, "Model")
ModelTextBox.DataBindings.Add("Text", objDataView, "Model")
SerialNumberTextBox.DataBindings.Add("Text", objDataView, "SerialNumber")
ConditionAtAcquisitionTextBox.DataBindings.Add("Text", objDataView, "ConditionAtAcquisition")
DateCurrentLocDateTimePicker.DataBindings.Add("Value", objDataView, "DateCurrentLoc", False, DataSourceUpdateMode.Never, Date.Now)
PurchasePriceTextBox.DataBindings.Add("Text", objDataView, "PurchasePrice")
SalvageValueTextBox.DataBindings.Add("Text", objDataView, "SalvageValue")
StatusIDTextBox.DataBindings.Add("Text", objDataView, "StatusID")
If objDataView.Table.Rows.Item("DateDel") IsNot DBNull.Value Then
DeletedOnDateTimePicker.DataBindings.Add("Value", objDataView, "DateDel", False, DataSourceUpdateMode.Never, Date.Now)
End If
DateWrittenoffDateTimePicker.DataBindings.Add("Value", objDataView, "DateWrittenoff", False, DataSourceUpdateMode.Never, Date.Now)
DateBoardedOffDateTimePicker.DataBindings.Add("Value", objDataView, "DateBoardedOff", False, DataSourceUpdateMode.Never, Date.Now)
AssetNameComboBox.DataBindings.Add("SelectedValue", objDataView, "AssetNameId")
AllocateAtComboBox.DataBindings.Add("SelectedValue", objDataView, "AllocatedTo")
OfficeListComboBox.DataBindings.Add("SelectedValue", objDataView, "OfficeId")
EmployeeComboBox.DataBindings.Add("SelectedValue", objDataView, "EmployeeID")
ProcuredAtComboBox.DataBindings.Add("SelectedValue", objDataView, "BranchID")
DonorNameComboBox.DataBindings.Add("SelectedValue", objDataView, "DonorID")
End Sub
|
|

December 29th, 2009, 10:25 AM
|
|
Registered User
|
|
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
DataBinding From DataView
Do not bother friends I have eventually sorted if out with as follows
Code:
If Not objDataView.Table.Rows(0).IsNull("DateCurrentLoc") Then
DateCurrentLocDateTimePicker.DataBindings.Add("Value", _ objDataView, "DateCurrentLoc")
End If
Quote:
Originally Posted by dserubiri
I have applied your binding techniiques with my database for managing assets and it seems to work perfectly in most of my controls except one of date where a get a error arising from DBNull value (where there is a null value in a date column). How can I first check for a DBNull value on a Dataview before databinding. Is there any one who can show me how to go about it. Following is my code:
Code:
Private Sub cmdSearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearchButton.Click
Try
Dim dsAssPart As New DataSet
Dim SelectedId As Integer
If AssetIDComboBox.SelectedValue IsNot Nothing Then
SelectedId = DirectCast(AssetIDComboBox.SelectedValue, Integer)
End If
Using Cnn As New SqlConnection("Data Source=DELEBYS-785804M;Initial Catalog=ASSETS MANAGER_beSQL1;" & _
"Integrated Security=True")
cmd = New SqlCommand
cmd.Connection = Cnn
cmd.CommandText = "AssetParticularsByID_sp"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@AssetID", SelectedId)
objDataAdapter = New SqlDataAdapter(cmd)
objDataAdapter.Fill(dsAssPart, "AssetParticulars")
End Using
objDataView = _
New DataView(dsAssPart.Tables("AssetParticulars"))
ClearBindings()
RestoreDataBindins()
Sub ClearBindings()
AssetIDTextBox.DataBindings.Clear()
FPAUAssetNoTextBox.DataBindings.Clear()
DateReceivedDateTimePicker.DataBindings.Clear()
AssetDescriptionTextBox.DataBindings.Clear()
ModelTextBox.DataBindings.Clear()
SerialNumberTextBox.DataBindings.Clear()
ConditionAtAcquisitionTextBox.DataBindings.Clear()
DateCurrentLocDateTimePicker.DataBindings.Clear()
PurchasePriceTextBox.DataBindings.Clear()
SalvageValueTextBox.DataBindings.Clear()
StatusIDTextBox.DataBindings.Clear()
DateWrittenoffDateTimePicker.DataBindings.Clear()
DateBoardedOffDateTimePicker.DataBindings.Clear()
DeletedOnDateTimePicker.DataBindings.Clear()
AssetNameComboBox.DataBindings.Clear()
AllocateAtComboBox.DataBindings.Clear()
OfficeListComboBox.DataBindings.Clear()
EmployeeComboBox.DataBindings.Clear()
ProcuredAtComboBox.DataBindings.Clear()
DonorNameComboBox.DataBindings.Clear()
End Sub
Sub RestoreDataBindins()
AssetIDTextBox.DataBindings.Add("Text", objDataView, "AssetID")
FPAUAssetNoTextBox.DataBindings.Add("Text", objDataView, "FPAUAssetNo")
DateReceivedDateTimePicker.DataBindings.Add("Value", objDataView, "DateReceived")
AssetDescriptionTextBox.DataBindings.Add("Text", objDataView, "Model")
ModelTextBox.DataBindings.Add("Text", objDataView, "Model")
SerialNumberTextBox.DataBindings.Add("Text", objDataView, "SerialNumber")
ConditionAtAcquisitionTextBox.DataBindings.Add("Text", objDataView, "ConditionAtAcquisition")
DateCurrentLocDateTimePicker.DataBindings.Add("Value", objDataView, "DateCurrentLoc", False, DataSourceUpdateMode.Never, Date.Now)
PurchasePriceTextBox.DataBindings.Add("Text", objDataView, "PurchasePrice")
SalvageValueTextBox.DataBindings.Add("Text", objDataView, "SalvageValue")
StatusIDTextBox.DataBindings.Add("Text", objDataView, "StatusID")
If objDataView.Table.Rows.Item("DateDel") IsNot DBNull.Value Then
DeletedOnDateTimePicker.DataBindings.Add("Value", objDataView, "DateDel", False, DataSourceUpdateMode.Never, Date.Now)
End If
DateWrittenoffDateTimePicker.DataBindings.Add("Value", objDataView, "DateWrittenoff", False, DataSourceUpdateMode.Never, Date.Now)
DateBoardedOffDateTimePicker.DataBindings.Add("Value", objDataView, "DateBoardedOff", False, DataSourceUpdateMode.Never, Date.Now)
AssetNameComboBox.DataBindings.Add("SelectedValue", objDataView, "AssetNameId")
AllocateAtComboBox.DataBindings.Add("SelectedValue", objDataView, "AllocatedTo")
OfficeListComboBox.DataBindings.Add("SelectedValue", objDataView, "OfficeId")
EmployeeComboBox.DataBindings.Add("SelectedValue", objDataView, "EmployeeID")
ProcuredAtComboBox.DataBindings.Add("SelectedValue", objDataView, "BranchID")
DonorNameComboBox.DataBindings.Add("SelectedValue", objDataView, "DonorID")
End Sub
|
|
|
 |