NET 3.5 - Connect to DB

5 posts, 0 answers
  1. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 15 Mar 2008 Link to this post

    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 
  2. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 16 Mar 2008 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 16 Mar 2008 Link to this post

    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"
  5. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 16 Mar 2008 Link to this post

    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
  6. Vassil Petev
    Admin
    Vassil Petev avatar
    1765 posts

    Posted 18 Mar 2008 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready