Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 28th, 2009, 08:01 AM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old December 29th, 2009, 10:25 AM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 View Post
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataBindings, p.417 member4953 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 June 4th, 2009 03:50 AM
dataGrid1.DataBindings.Add() in PDA mahen_pali C# 2005 1 June 3rd, 2008 05:36 AM
DataBindings: LogOnInfo peter2004 Crystal Reports 0 June 24th, 2005 12:08 PM



All times are GMT -4. The time now is 06:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.