This is a migrated thread and some comments may be shown as answers.

NET 3.5 - Connect to DB

4 Answers 73 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chase Florell
Top achievements
Rank 1
Chase Florell asked on 15 Mar 2008, 06:59 AM
OK so I am new to both .NET 3.5 and Winforms.  I have experience connecting to a db in the web.config file, but when it comes to the app.config, I am having difficulty.

I am trying to populate the ComboBox with data from a Stored Procedure.

Can anyone point me in the right direction, I think I must be close.

Imports System  
Imports System.Data  
Imports System.Configuration  
Imports System.Data.SqlClient  
Imports System.Data.CommandType  
 
Public Class Form_Donations  
 
    Private Sub Form_Donations_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        Dim Conn As SqlConnection = New SqlConnection(ConnStr)  
        Dim sqlcmd As SqlCommand = New SqlCommand("npoGetHousehold_NameID", Conn)  
        sqlcmd.CommandType = StoredProcedure  
 
        Conn.Open()  
        Dim rs As SqlClient.SqlDataReader  
        rs = sqlcmd.ExecuteReader()  
 
        If rs.HasRows Then 
            Try 
                RadComboBox2.DataSource = rs  
                RadComboBox2.DisplayMember = "Name" 
                RadComboBox2.ValueMember = "ID" 
            Catch ex As Exception  
 
            End Try 
            Conn.Close()  
            Conn.Dispose()  
        End If 
 
    End Sub 

4 Answers, 1 is accepted

Sort by
0
Chase Florell
Top achievements
Rank 1
answered on 16 Mar 2008, 07:12 AM
Anyone?

I would actually consider going to a DAL if I can be shown an example or pointed in the right direction.

I have never used DAL's before.
0
Chase Florell
Top achievements
Rank 1
answered on 16 Mar 2008, 09:13 PM
Well I have gotten this far but it is not binding to my data.

 Dim con As SqlConnection = New SqlConnection(My.Settings.npo_trak_sqlConnectionString)  
        Dim sqlcmd As SqlCommand = New SqlCommand("npoGetHousehold_NameID", con)  
        sqlcmd.CommandType = StoredProcedure  
 
        con.Open()  
        Dim rs As SqlClient.SqlDataReader  
        rs = sqlcmd.ExecuteReader()  
 
        If rs.HasRows Then 
            Try 
                RadComboBox2.DisplayMember = "Name" 
                RadComboBox2.ValueMember = "ID" 
                RadComboBox2.DataSource = rs  
            Catch ex As Exception  
 
            End Try 
            con.Close()  
            con.Dispose()  
        End If 

I am getting the following error
"Bad Data Source For Complex Binding"
0
Chase Florell
Top achievements
Rank 1
answered on 16 Mar 2008, 10:12 PM
Well I have decided to change my strategy a little and try an use xsd data sources, but am struggling with how to do it still.

I have created a datasource called "npoGetHousehold_NameID" and then dropped my stored procedure onto it.

Then I tried using

RadCombobox2.DataSource = npoGetHousehold_NameID
RadCombobox2.DisplayMember = "Name"
RadCombobox2.ValueMember = "ID"

But that doesnt seem to be working.  'npoGetHousehold_NameID' is a type and cannot be used as an expression.

How can I break this down the best way to reduce the amound of code in my codebehind
0
Vassil Petev
Telerik team
answered on 18 Mar 2008, 10:21 AM
Hello Chase,

Your question here seems to be directly related to the one you have posted in your support ticket. We will reply there shortly.


Regards,
Vassil
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Chase Florell
Top achievements
Rank 1
Answers by
Chase Florell
Top achievements
Rank 1
Vassil Petev
Telerik team
Share this question
or