Re: Populating a combo using n-Tier datasets by Wayne
Wayne
Tue Jul 08 14:56:37 CDT 2003
This is a multi-part message in MIME format.
------=_NextPart_000_00FF_01C34558.BFDFA710
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
In my code that I use to populate Comboboxes I have the following lines =
:
ComboBox1.BeginUpdate()
ComboBox1.DataSource =3D ....
ComboBox1.ValueMember =3D ...
ComboBox1.DisplayMember =3D ...
ComboBox1.EndUpdate()
Are you not able to see the contents of your dataset when it comes out =
of FillCtlCbo?
Wayne=20
"Bruce Parr" <bparr@fulltilt.com> wrote in message =
news:%23D8iwFWRDHA.2148@TK2MSFTNGP11.phx.gbl...
OK guys,
I have two replies, both of which I really appreciate.
Wayne, there is no databind since I am using this for win32, not web.
Ibrahim, I am following almost exactly whayt you are doing, but can't =
seem
to get the combo to populate. Not sure why yet...Code is all below
***Presentation***
Private Sub FillStudents()
Dim objSupport As EGI.Support
Dim ds As New DataSet()
ComboBox1.ValueMember =3D "StudentID"
ComboBox1.DisplayMember =3D "FullName"
objSupport =3D New EGI.Support(True, "", gs_SQLConnString)
ds =3D objSupport.FillCtlCbo("STU_Students", "FullName", "StudentID",
ComboBox1)
ComboBox1.DataSource =3D ds
objSupport =3D Nothing
End Sub
***Support***
Public Function FillCtlCbo(ByVal sTblName As String, ByVal sFldName As
String, ByVal sIDName As String, ByVal sCboName As ComboBox, Optional =
ByVal
sUserID As String =3D "") As DataSet
Dim objCtl As DataHandler
Dim strSQl As String
Dim ds As New DataSet()
objCtl =3D New DataHandler(cblnIsSQL, cstrAccessDB, =
cstrSQLConnectionString)
strSQl =3D ""
If sTblName =3D "STU_Students" Then
strSQl =3D "SELECT [" & sIDName & "], [" & sFldName & "], =
MiddleName FROM
" & sTblName
strSQl =3D strSQl & " ORDER BY [" & sFldName & "]"
Else
strSQl =3D "SELECT [" & sIDName & "], [" & sFldName & "] FROM " & =
sTblName
strSQl =3D strSQl & " ORDER BY [" & sFldName & "]"
End If
ds =3D objCtl.RecordGetDS(strSQl)
If Not objCtl Is Nothing Then
objCtl.Dispose()
objCtl =3D Nothing
End If
If Not rstCtl Is Nothing Then rstCtl =3D Nothing
Return ds
End Function
***Data***
Public Function RecordGetDS(ByVal sSQL As String) As DataSet
Dim objConn As OleDb.OleDbConnection
Dim da As OleDb.OleDbDataAdapter
Dim ds As New DataSet()
'**** Connect to Database
objConn =3D New OleDb.OleDbConnection()
If Not cblnIsSQL Then
objConn.ConnectionString =3D GetConnectionString(cstrAccessDB)
objConn.Open()
Else
objConn.ConnectionString =3D cstrSQLConnectionString
sSQL =3D Replace(sSQL, "=3D True", "=3D 1", 1)
sSQL =3D Replace(sSQL, "=3DTrue", "=3D1", 1)
sSQL =3D Replace(sSQL, "=3D False", "=3D 0", 1)
sSQL =3D Replace(sSQL, "=3DFalse", "=3D0", 1)
sSQL =3D Replace(sSQL, "=3D#", "=3D'", 1)
sSQL =3D Replace(sSQL, "<#", "<'", 1)
sSQL =3D Replace(sSQL, ">#", ">'", 1)
sSQL =3D Replace(sSQL, "=3D #", "=3D '", 1)
sSQL =3D Replace(sSQL, "< #", "< '", 1)
sSQL =3D Replace(sSQL, "> #", "> '", 1)
sSQL =3D Replace(sSQL, ",#", ",'", 1)
sSQL =3D Replace(sSQL, ", #", ", '", 1)
sSQL =3D Replace(sSQL, "#,", "',", 1)
sSQL =3D Replace(sSQL, "# ", "' ", 1)
If Right(sSQL, 1) =3D "#" Then
sSQL =3D Replace(sSQL, "#", "'")
End If
End If
da =3D New OleDb.OleDbDataAdapter(sSQL, objConn.ConnectionString)
da.Fill(ds)
If Not objConn Is Nothing Then
objConn.Close()
objConn.Dispose()
objConn =3D Nothing
End If
If Not da Is Nothing Then
da.Dispose()
da =3D Nothing
End If
Return ds
End Function
"Bruce Parr" <bparr@fulltilt.com> wrote in message
news:eFg3kiVRDHA.940@TK2MSFTNGP11.phx.gbl...
> All,
>
> I would love an answer to this issue...
>
> I am trying to populate a combo using DataSets in an n-tier model. I =
have
> the function in the form called FillCombo send the SQL paramters to =
a
> support DLL. The support DLL in turn calls the data layer to =
actually
> retrieve the data from the database. What I need to be able to do is =
pass
> the DataSet from the data layer through the support layer to the
> presentation layer. I am stepping through the code and see the data
populate
> at the data layer. I cannot see if it is getting through from there
though.
>
> ComboBox1.DataSource =3D objSupport.FillCtl(sSQL) (returns a =
dataset)
>
> Public Function FillCtl(sSQL...) as Dataset
> ...
> ds =3D objDB.RecordGet(sSQL)
> FillCtl =3D ds.copy
>
> ...
>
>
> Anyone have any examples or suggestions? I have tried populating the
DataSet
> using a DataAdapter, then using .copy to copy the dataset to the =
function
so
> it gets returned. This is not working...
>
> Thanks,
> Bruce
>
>
>
>
------=_NextPart_000_00FF_01C34558.BFDFA710
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>In my code that I use to populate =
Comboboxes I have=20
the following lines :</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>ComboBox1.BeginUpdate()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>ComboBox1.DataSource =3D =
....</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>ComboBox1.ValueMember =3D =
...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>ComboBox1.DisplayMember =3D =
...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>ComboBox1.EndUpdate()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Are you not able to see the contents of =
your=20
dataset when it comes out of <FONT face=3D"Times New Roman"=20
size=3D3>FillCtlCbo?</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman"=20
size=3D3></FONT> </DIV></FONT>
<DIV><FONT face=3DVerdana size=3D2>Wayne </FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2><BR> </DIV></FONT>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Bruce Parr" <<A=20
href=3D"mailto:bparr@fulltilt.com">bparr@fulltilt.com</A>> wrote in =
message=20
<A=20
=
href=3D"news:%23D8iwFWRDHA.2148@TK2MSFTNGP11.phx.gbl">news:%23D8iwFWRDHA.=
2148@TK2MSFTNGP11.phx.gbl</A>...</DIV>OK=20
guys,<BR><BR>I have two replies, both of which I really=20
appreciate.<BR><BR>Wayne, there is no databind since I am using this =
for=20
win32, not web.<BR>Ibrahim, I am following almost exactly whayt you =
are doing,=20
but can't seem<BR>to get the combo to populate. Not sure why =
yet...Code is all=20
below<BR><BR>***Presentation***<BR>Private Sub =
FillStudents()<BR><BR>Dim=20
objSupport As EGI.Support<BR>Dim ds As New=20
DataSet()<BR><BR>ComboBox1.ValueMember =3D=20
"StudentID"<BR>ComboBox1.DisplayMember =3D "FullName"<BR>objSupport =
=3D New=20
EGI.Support(True, "", gs_SQLConnString)<BR>ds =3D=20
objSupport.FillCtlCbo("STU_Students", "FullName",=20
"StudentID",<BR>ComboBox1)<BR>ComboBox1.DataSource =3D =
ds<BR>objSupport =3D=20
Nothing<BR><BR>End Sub<BR><BR>***Support***<BR><BR>Public Function=20
FillCtlCbo(ByVal sTblName As String, ByVal sFldName As<BR>String, =
ByVal=20
sIDName As String, ByVal sCboName As ComboBox, Optional =
ByVal<BR>sUserID As=20
String =3D "") As DataSet<BR>Dim objCtl As DataHandler<BR>Dim strSQl =
As=20
String<BR>Dim ds As New DataSet()<BR><BR>objCtl =3D New =
DataHandler(cblnIsSQL,=20
cstrAccessDB, cstrSQLConnectionString)<BR><BR>strSQl =3D ""<BR>If =
sTblName =3D=20
"STU_Students" Then<BR> strSQl =3D "SELECT [" & =
sIDName=20
& "], [" & sFldName & "], MiddleName FROM<BR>" &=20
sTblName<BR> strSQl =3D strSQl & " ORDER BY [" =
&=20
sFldName & "]"<BR>Else<BR> strSQl =3D "SELECT [" =
&=20
sIDName & "], [" & sFldName & "] FROM " &=20
sTblName<BR> strSQl =3D strSQl & " ORDER BY [" =
&=20
sFldName & "]"<BR>End If<BR><BR>ds =3D =
objCtl.RecordGetDS(strSQl)<BR>If Not=20
objCtl Is Nothing Then<BR> =20
objCtl.Dispose()<BR> objCtl =3D Nothing<BR>End =
If<BR><BR>If=20
Not rstCtl Is Nothing Then rstCtl =3D Nothing<BR>Return ds<BR><BR>End=20
Function<BR><BR>***Data***<BR><BR>Public Function RecordGetDS(ByVal =
sSQL As=20
String) As DataSet<BR>Dim objConn As OleDb.OleDbConnection<BR>Dim da =
As=20
OleDb.OleDbDataAdapter<BR>Dim ds As New DataSet()<BR><BR>'**** Connect =
to=20
Database<BR><BR>objConn =3D New OleDb.OleDbConnection()<BR>If Not =
cblnIsSQL=20
Then<BR> objConn.ConnectionString =3D=20
GetConnectionString(cstrAccessDB)<BR> =20
objConn.Open()<BR>Else<BR> objConn.ConnectionString =
=3D=20
cstrSQLConnectionString<BR> sSQL =3D Replace(sSQL, =
"=3D True",=20
"=3D 1", 1)<BR> sSQL =3D Replace(sSQL, "=3DTrue", =
"=3D1",=20
1)<BR> sSQL =3D Replace(sSQL, "=3D False", "=3D 0",=20
1)<BR> sSQL =3D Replace(sSQL, "=3DFalse", "=3D0",=20
1)<BR> sSQL =3D Replace(sSQL, "=3D#", "=3D'",=20
1)<BR> sSQL =3D Replace(sSQL, "<#", "<'",=20
1)<BR> sSQL =3D Replace(sSQL, ">#", ">'",=20
1)<BR> sSQL =3D Replace(sSQL, "=3D #", "=3D '",=20
1)<BR> sSQL =3D Replace(sSQL, "< #", "< '",=20
1)<BR> sSQL =3D Replace(sSQL, "> #", "> '",=20
1)<BR> sSQL =3D Replace(sSQL, ",#", ",'",=20
1)<BR> sSQL =3D Replace(sSQL, ", #", ", '",=20
1)<BR> sSQL =3D Replace(sSQL, "#,", "',",=20
1)<BR> sSQL =3D Replace(sSQL, "# ", "' ",=20
1)<BR><BR> If Right(sSQL, 1) =3D "#"=20
Then<BR> sSQL =3D =
Replace(sSQL, "#",=20
"'")<BR> End If<BR>End If<BR><BR><BR><BR>da =3D New=20
OleDb.OleDbDataAdapter(sSQL,=20
objConn.ConnectionString)<BR><BR>da.Fill(ds)<BR><BR>If Not objConn Is =
Nothing=20
Then<BR> objConn.Close()<BR> =20
objConn.Dispose()<BR> objConn =3D Nothing<BR>End =
If<BR><BR>If=20
Not da Is Nothing Then<BR> =20
da.Dispose()<BR> da =3D Nothing<BR>End =
If<BR><BR>Return=20
ds<BR><BR>End Function<BR><BR><BR>"Bruce Parr" <<A=20
href=3D"mailto:bparr@fulltilt.com">bparr@fulltilt.com</A>> wrote in =
message<BR><A=20
=
href=3D"news:eFg3kiVRDHA.940@TK2MSFTNGP11.phx.gbl">news:eFg3kiVRDHA.940@T=
K2MSFTNGP11.phx.gbl</A>...<BR>>=20
All,<BR>><BR>> I would love an answer to this =
issue...<BR>><BR>> I=20
am trying to populate a combo using DataSets in an n-tier model. I=20
have<BR>> the function in the form called FillCombo send the SQL =
paramters=20
to a<BR>> support DLL. The support DLL in turn calls the data layer =
to=20
actually<BR>> retrieve the data from the database. What I need to =
be able=20
to do is pass<BR>> the DataSet from the data layer through the =
support=20
layer to the<BR>> presentation layer. I am stepping through the =
code and=20
see the data<BR>populate<BR>> at the data layer. I cannot see if it =
is=20
getting through from there<BR>though.<BR>><BR>> =
ComboBox1.DataSource =3D=20
objSupport.FillCtl(sSQL) (returns a dataset)<BR>><BR>> Public =
Function=20
FillCtl(sSQL...) as Dataset<BR>> =20
...<BR>> ds =3D=20
objDB.RecordGet(sSQL)<BR>> FillCtl =3D=20
ds.copy<BR>><BR>> =
...<BR>><BR>><BR>>=20
Anyone have any examples or suggestions? I have tried populating=20
the<BR>DataSet<BR>> using a DataAdapter, then using .copy to copy =
the=20
dataset to the function<BR>so<BR>> it gets returned. This is not=20
working...<BR>><BR>> Thanks,<BR>>=20
=
Bruce<BR>><BR>><BR>><BR>><BR><BR></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_00FF_01C34558.BFDFA710--