|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
dataadapter and componenta 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 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 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 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
Other interesting topics
Memory leak in OleDbCommand.ExecuteNonQuery()?
C# and ADO.Net - Cheap Question! closing connection not by design Architecture: One Producer, Many Consumers Filter Dataset SQLConnection connection pool issue No cursor when compared with ADO How does ADO.NET handle transactions when the connection is broken Strange slow down with imbricated DataReader (Oracle, c#) XML Schema (XSD) and ADO.net DataSet - limitations mapping between them |
|||||||||||||||||||||||