ComboBox not display in VB.Net 2003


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: ComboBox not display in VB.Net 2003

Threaded View

  1. #1
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319

    ComboBox not display in VB.Net 2003

    Hi All,

    Greetings. I am learning to fill DataGrid and ComboBoxes using CLASS.

    Here is the scenerio:-
    I have a User Interface screen. On Page Load, the event will load and fill DataGrid and both the comboboxes , City and Country using Stored Procedures. I am using CLASS DATASERVICE to create sqlDataAdapter and DataTable.

    I am facing two problems :-

    1. One of the combobox is displaying "System.Data.DataRowView"
    2. and the combobox text should be blank on Page Load.

    Listed below are codes snippet and screen dump attached.

    Dim DServ As DataService
    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim da As SqlDataAdapter

    Private Sub BtnLoad_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles BtnLoad.Click

    FFillDataGrid()
    End Sub

    Private Sub FFillDataGrid()
    'using Data Service class
    Try
    With Me.DataGrid1
    DServ = New DataService
    .DataSource = DServ.GetDataAdapter("SPGetAllCustomers", "Customers")
    .ReadOnly = True
    End With

    Catch ex As Exception
    Throw New Exception(ex.Message)

    Finally

    End Try

    End Sub

    .............................
    Private Sub FFillComboBox()

    Dim ds As DataSet = New DataSet
    DServ = New DataService

    Try
    With Me.cboCity
    .DataSource = DServ.GetDataAdapter("SPGetCity", "City")
    .DisplayMember = "City"
    .ValueMember = "City"
    End With

    With Me.cboCountry
    .DataSource = DServ.GetDataAdapter("SPGetCountry", "Country")
    .DisplayMember = "Country"
    .DisplayMember = "Country"
    End With

    Catch ex As Exception
    Throw New Exception(ex.Message)

    Finally
    ds.Clear()
    End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load

    FFillDataGrid()
    FFillComboBox()

    End Sub
    End Class

    ....................

    Public Class DataService

    Dim sqlConn As SqlConnection
    Dim sqlDa As SqlDataAdapter
    Dim sqlDS As DataSet

    Public Function GetDataAdapter(ByVal iSql As String, _
    ByVal TableName As String) As DataTable

    Try
    sqlConn = New SqlConnection(connstr)
    sqlDa = New SqlDataAdapter(iSql, sqlConn)

    'instantiate GetData
    GetDataAdapter = New DataTable(TableName)
    With sqlDa
    .Fill(GetDataAdapter)
    End With

    Catch ex As Exception
    Throw New Exception(ex.Message)

    Finally
    sqlConn.Close()
    End Try

    End Function

    End Class

    ....................................
    STORED PROCEDURES
    ...................................
    CREATE PROCEDURE dbo.SPGetCity
    AS
    Select Distinct City from Customers
    Order by City
    GO


    CREATE PROCEDURE dbo.SPGetCountry
    AS
    Select Distinct Country from Customers
    Order by Country
    GO


    CREATE PROCEDURE dbo.SPGetAllCustomers
    AS
    Select Customerid, CompanyName, Address, City, Region, Country from Customers
    Order by CompanyName
    GO
    Attached Images Attached Images
    Cheers,
    Lennie

Similar Threads

  1. Replies: 2
    Last Post: 08-27-2003, 10:11 AM
  2. VB.NET 2003 Std Edition to Include Upgrade Wizard
    By Patrick Troughton in forum .NET
    Replies: 2
    Last Post: 02-23-2003, 06:22 PM
  3. A moderate view.
    By Paul Mc in forum .NET
    Replies: 214
    Last Post: 06-01-2001, 07:27 AM
  4. Why I like VB.NET
    By Tom Cabanski in forum .NET
    Replies: 74
    Last Post: 03-14-2001, 03:30 PM
  5. VB.NET: 3 points of view
    By David Kroll in forum .NET
    Replies: 33
    Last Post: 02-13-2001, 10:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center