Home All Groups Group Topic Archive Search About

dataadapter and component

Author
1 Apr 2005 5:33 PM
Kurt Schroeder

I'm creating a component that contains a function. This function is to return
a data set of state values (AL,IL,TN,CA,...). I'm new to dataadapters this is
my first, but something just doesn't seem right.

the function return a dataset, but do it need to define a dataset in the
body of the function as well as in the calling routine?
2. can i bind this dataset to two different drop down lists?

here is my function.

Public Class states
    Inherits System.ComponentModel.Component
    Public Function GetStates() As DataSet
        Dim ddlStates As DataSet = New DataSet

        Dim strcon As String = "DSN=SE;"
        Dim conSE As New OdbcConnection(strcon)
        Dim strSQL As String = "select staStateName, staLongName from sta
where 1=1 order by staStateName"
        Dim daStates As OdbcDataAdapter
        daStates = New OdbcDataAdapter(strSQL, conSE)
        'Fill dataset
        conSE.Open()
        daStates.Fill(ddlStates, "states")
        conSE.Close()
        Return ddlStates
    End Function
Author
3 Apr 2005 2:49 AM
Bonnie Berent [C# MVP]
OK, Kurt, so what doesn't seem right? Is this code working or not?  The code,
as it is, looks fine.

As far as binding to two different dropdown lists, I'm not 100% sure. I work
with WinForms and you have to use separate DataSources for ComboBoxes there.
I'm not sure if the same applies with a WebForm's DropDownList.

~~Bonnie



Show quoteHide quote
"Kurt Schroeder" wrote:

> I'm creating a component that contains a function. This function is to return
> a data set of state values (AL,IL,TN,CA,...). I'm new to dataadapters this is
> my first, but something just doesn't seem right.
>
> the function return a dataset, but do it need to define a dataset in the
> body of the function as well as in the calling routine?
> 2. can i bind this dataset to two different drop down lists?
>
> here is my function.
>
> Public Class states
>     Inherits System.ComponentModel.Component
>     Public Function GetStates() As DataSet
>         Dim ddlStates As DataSet = New DataSet
>
>         Dim strcon As String = "DSN=SE;"
>         Dim conSE As New OdbcConnection(strcon)
>         Dim strSQL As String = "select staStateName, staLongName from sta
> where 1=1 order by staStateName"
>         Dim daStates As OdbcDataAdapter
>         daStates = New OdbcDataAdapter(strSQL, conSE)
>         'Fill dataset
>         conSE.Open()
>         daStates.Fill(ddlStates, "states")
>         conSE.Close()
>         Return ddlStates
>     End Function
Are all your drivers up to date? click for free checkup

Author
4 Apr 2005 1:25 PM
Kurt Schroeder
thank's for the response,
It seems the same appilies here. There is a way around it , but that  would
mean adding the items via a loop w/o binding.
thank you
kes

Show quoteHide quote
"Bonnie Berent [C# MVP]" wrote:

> OK, Kurt, so what doesn't seem right? Is this code working or not?  The code,
> as it is, looks fine.
>
> As far as binding to two different dropdown lists, I'm not 100% sure. I work
> with WinForms and you have to use separate DataSources for ComboBoxes there.
> I'm not sure if the same applies with a WebForm's DropDownList.
>
> ~~Bonnie
>
>
>
> "Kurt Schroeder" wrote:
>
> > I'm creating a component that contains a function. This function is to return
> > a data set of state values (AL,IL,TN,CA,...). I'm new to dataadapters this is
> > my first, but something just doesn't seem right.
> >
> > the function return a dataset, but do it need to define a dataset in the
> > body of the function as well as in the calling routine?
> > 2. can i bind this dataset to two different drop down lists?
> >
> > here is my function.
> >
> > Public Class states
> >     Inherits System.ComponentModel.Component
> >     Public Function GetStates() As DataSet
> >         Dim ddlStates As DataSet = New DataSet
> >
> >         Dim strcon As String = "DSN=SE;"
> >         Dim conSE As New OdbcConnection(strcon)
> >         Dim strSQL As String = "select staStateName, staLongName from sta
> > where 1=1 order by staStateName"
> >         Dim daStates As OdbcDataAdapter
> >         daStates = New OdbcDataAdapter(strSQL, conSE)
> >         'Fill dataset
> >         conSE.Open()
> >         daStates.Fill(ddlStates, "states")
> >         conSE.Close()
> >         Return ddlStates
> >     End Function
Author
4 Apr 2005 2:17 PM
Bonnie Berent [C# MVP]
Kurt,

But, you don't have to get the same DataSet from your database two tiimes
.... you can get it once, and then for your second instance of it (for you
second dropdownlist), you can just copy it.

~~Bonnie


Show quoteHide quote
"Kurt Schroeder" wrote:

> thank's for the response,
> It seems the same appilies here. There is a way around it , but that  would
> mean adding the items via a loop w/o binding.
> thank you
> kes
>
> "Bonnie Berent [C# MVP]" wrote:
>
> > OK, Kurt, so what doesn't seem right? Is this code working or not?  The code,
> > as it is, looks fine.
> >
> > As far as binding to two different dropdown lists, I'm not 100% sure. I work
> > with WinForms and you have to use separate DataSources for ComboBoxes there.
> > I'm not sure if the same applies with a WebForm's DropDownList.
> >
> > ~~Bonnie
> >
> >
> >
> > "Kurt Schroeder" wrote:
> >
> > > I'm creating a component that contains a function. This function is to return
> > > a data set of state values (AL,IL,TN,CA,...). I'm new to dataadapters this is
> > > my first, but something just doesn't seem right.
> > >
> > > the function return a dataset, but do it need to define a dataset in the
> > > body of the function as well as in the calling routine?
> > > 2. can i bind this dataset to two different drop down lists?
> > >
> > > here is my function.
> > >
> > > Public Class states
> > >     Inherits System.ComponentModel.Component
> > >     Public Function GetStates() As DataSet
> > >         Dim ddlStates As DataSet = New DataSet
> > >
> > >         Dim strcon As String = "DSN=SE;"
> > >         Dim conSE As New OdbcConnection(strcon)
> > >         Dim strSQL As String = "select staStateName, staLongName from sta
> > > where 1=1 order by staStateName"
> > >         Dim daStates As OdbcDataAdapter
> > >         daStates = New OdbcDataAdapter(strSQL, conSE)
> > >         'Fill dataset
> > >         conSE.Open()
> > >         daStates.Fill(ddlStates, "states")
> > >         conSE.Close()
> > >         Return ddlStates
> > >     End Function

Bookmark and Share

Post Thread options