473,657 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How Do I add records to a Listbox control ?

Hi;

I am a novice asp.net developer who would like to create
a dataset-table and then use the datatable.selec t cmd. to
look up a value passed from the web calender control. The
value(s) would then be used to populate a listbox on a
web form. I keep getting an error that says that in the
datatable.SELEC T statement i.e. mytable.select( "column1 =
= '" & aVariable & "'"), that the column1 can't be found.
I can run this program code in a windows program and it
works fine. What am I missing, code wise, to make the
code run under ASP.net ?

Here is the following code that I tried. It is
called from the date selected event of the web calender
control.

Thanks,

Gordon

---------------------------------------------------------

Public Sub SetUpDataBindin g()

Dim datConn As String = "Integrated
Security=SSPI;I nitial Catalog=DocsDat es;Data Source=
(local)\vsdotne t"
Dim cnDocDates As New SqlConnection(d atConn)

Try

Dim cmdGetCases As New SqlCommand
("CMasterSelect Command", cnDocDates)
Dim daCases As New SqlDataAdapter( "SELECT
case_id, lname, case_status from CaseMaster", cnDocDates)
Dim daDocs As New SqlDataAdapter( "SELECT
case_id, document_nme, doc_dte_start, " & _
"doc_dte_du e, comments from CaseDocs where
case_id in " & _
"(SELECT case_id from CaseMaster)",
cnDocDates)
Dim ds As New DataSet
daDocs.Fill(dsC ases, "tblCaseDoc s")
Session("dsCase s") = dsCases

holdDte = Today
Catch ex As System.Data.Sql Client.SqlExcep tion

If
HttpContext.Cur rent.Request.Us erHostAddress = "129.0.0.5"
Then
Session("Curren tError") = ex.Message
Else
Session("Curren tError") = "Error
processing page."
End If
Server.Transfer ("ApplicationEr ror.aspx")
Finally
' cnDocDates.Clos e()
End Try

End Sub
Public Sub ListBoxFill() ((( This called when a date
is selected on the calendar web control )))))

Dim myCol As DataColumn
Dim myRow As DataRow
Dim currRows() As DataRow
Dim nRow As DataRow()
Dim irow As DataRow

nRow = tblCaseDocs.Sel ect("doc_dte_du e = '" &
holdDte.ToStrin g & "'") ((( I get an error on the web page
when I click on a date saying that the table column
[doc_dte_due] isn't found ?? )))

ListBox1.Items. Clear()

For Each irow In nRow
ListBox1.Items. Add(irow("case_ id") & " " &
irow("Document_ Nme"))
Next

ListBox1.DataBi nd() (((( Do I need this ? )))

End Sub

Nov 18 '05 #1
2 1448
ListBox1.DataBi nd() (((( Do I need this ? )))
No you don't

A dataset is an in-memory representation of the datasource. A datatable is
representation of a particular table. So there wouldn't really be a
dataset-table.

For the select to work it has to work on the actual name of the column so if
your select used "column_dat e" then you would not be allowed to use column1
you would have to use the "column_dat e" string to identify the column.

What you will need to do is something like this, since the dataset is
already stored in dsCases, just retrieve it and bind it to the listbox,
there is no need to go back to the database for it.

//c# code btw
//pull it out of session and cast it back as a dataset because it is plain
object
DataSet ds = (DataSet) Session("dsCase s")

//tell it which field you want to display in the listbox because it doesnt
know
ListBox1.DataTe xtField = "column_name_fr om_select_query "

//tell it where the data is
ListBox1.DataSo urce = ds;

//then tell it to display itself
ListBox1.DataBi nd()

--
Regards,
Alvin Bruney
Got Tidbits? Get it here
www.networkip.net/tidbits
"Gordon" <an*******@disc ussions.microso ft.com> wrote in message
news:95******** *************** *****@phx.gbl.. .
Hi;

I am a novice asp.net developer who would like to create
a dataset-table and then use the datatable.selec t cmd. to
look up a value passed from the web calender control. The
value(s) would then be used to populate a listbox on a
web form. I keep getting an error that says that in the
datatable.SELEC T statement i.e. mytable.select( "column1 =
= '" & aVariable & "'"), that the column1 can't be found.
I can run this program code in a windows program and it
works fine. What am I missing, code wise, to make the
code run under ASP.net ?

Here is the following code that I tried. It is
called from the date selected event of the web calender
control.

Thanks,

Gordon

---------------------------------------------------------

Public Sub SetUpDataBindin g()

Dim datConn As String = "Integrated
Security=SSPI;I nitial Catalog=DocsDat es;Data Source=
(local)\vsdotne t"
Dim cnDocDates As New SqlConnection(d atConn)

Try

Dim cmdGetCases As New SqlCommand
("CMasterSelect Command", cnDocDates)
Dim daCases As New SqlDataAdapter( "SELECT
case_id, lname, case_status from CaseMaster", cnDocDates)
Dim daDocs As New SqlDataAdapter( "SELECT
case_id, document_nme, doc_dte_start, " & _
"doc_dte_du e, comments from CaseDocs where
case_id in " & _
"(SELECT case_id from CaseMaster)",
cnDocDates)
Dim ds As New DataSet
daDocs.Fill(dsC ases, "tblCaseDoc s")
Session("dsCase s") = dsCases

holdDte = Today
Catch ex As System.Data.Sql Client.SqlExcep tion

If
HttpContext.Cur rent.Request.Us erHostAddress = "129.0.0.5"
Then
Session("Curren tError") = ex.Message
Else
Session("Curren tError") = "Error
processing page."
End If
Server.Transfer ("ApplicationEr ror.aspx")
Finally
' cnDocDates.Clos e()
End Try

End Sub
Public Sub ListBoxFill() ((( This called when a date
is selected on the calendar web control )))))

Dim myCol As DataColumn
Dim myRow As DataRow
Dim currRows() As DataRow
Dim nRow As DataRow()
Dim irow As DataRow

nRow = tblCaseDocs.Sel ect("doc_dte_du e = '" &
holdDte.ToStrin g & "'") ((( I get an error on the web page
when I click on a date saying that the table column
[doc_dte_due] isn't found ?? )))

ListBox1.Items. Clear()

For Each irow In nRow
ListBox1.Items. Add(irow("case_ id") & " " &
irow("Document_ Nme"))
Next

ListBox1.DataBi nd() (((( Do I need this ? )))

End Sub

Nov 18 '05 #2
Thanks for your help Alvin.

-----Original Message-----
Hi;

I am a novice asp.net developer who would like to create
a dataset-table and then use the datatable.selec t cmd. to
look up a value passed from the web calender control. The
value(s) would then be used to populate a listbox on a
web form. I keep getting an error that says that in the
datatable.SELE CT statement i.e. mytable.select( "column1 =
= '" & aVariable & "'"), that the column1 can't be found.I can run this program code in a windows program and it
works fine. What am I missing, code wise, to make the
code run under ASP.net ?

Here is the following code that I tried. It is
called from the date selected event of the web calender
control.

Thanks,

Gordon

---------------------------------------------------------

Public Sub SetUpDataBindin g()

Dim datConn As String = "Integrated
Security=SSPI; Initial Catalog=DocsDat es;Data Source=
(local)\vsdotn et"
Dim cnDocDates As New SqlConnection(d atConn)

Try

Dim cmdGetCases As New SqlCommand
("CMasterSelec tCommand", cnDocDates)
Dim daCases As New SqlDataAdapter( "SELECT
case_id, lname, case_status from CaseMaster", cnDocDates)
Dim daDocs As New SqlDataAdapter( "SELECT
case_id, document_nme, doc_dte_start, " & _
"doc_dte_du e, comments from CaseDocs where
case_id in " & _
"(SELECT case_id from CaseMaster)",
cnDocDates)
Dim ds As New DataSet
daDocs.Fill(dsC ases, "tblCaseDoc s")
Session("dsCase s") = dsCases

holdDte = Today
Catch ex As System.Data.Sql Client.SqlExcep tion

If
HttpContext.Cu rrent.Request.U serHostAddress = "129.0.0.5"Then
Session("Curren tError") = ex.Message
Else
Session("Curren tError") = "Error
processing page."
End If
Server.Transfer ("ApplicationEr ror.aspx")
Finally
' cnDocDates.Clos e()
End Try

End Sub
Public Sub ListBoxFill() ((( This called when a dateis selected on the calendar web control )))))

Dim myCol As DataColumn
Dim myRow As DataRow
Dim currRows() As DataRow
Dim nRow As DataRow()
Dim irow As DataRow

nRow = tblCaseDocs.Sel ect("doc_dte_du e = '" &
holdDte.ToStri ng & "'") ((( I get an error on the web pagewhen I click on a date saying that the table column
[doc_dte_due] isn't found ?? )))

ListBox1.Items. Clear()

For Each irow In nRow
ListBox1.Items. Add(irow("case_ id") & " " &
irow("Document _Nme"))
Next

ListBox1.DataBi nd() (((( Do I need this ? )))

End Sub

.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
453
by: Danny | last post by:
How to allow users to select a set of records and then let them change a field for all these records at once? I would like to do this in code on a form. I will have a form with tabular view of records, and I guess they will select more than one record with the SHIFT key, then they can modify a whole bunch of records at once. Thanks
3
2664
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want to print the selected records of the selected month > Can any one advise on the below Below is code i am trying to adapt (Thanks Don) 1.This first part is causing me problems so i have deleted it as it strikes me that it is looking for a...
2
1473
by: ndunwoodie | last post by:
I have table with 5 records each with 5 fields. I would like to have these records appear simultaneously on a form (i was thinking of some kind of bound control - not a listbox). I then plan to put a command button next to each record so that a user could select the particular record. Clicking the command button will cause the record to be written to a different table along with the user's name (I know how to do this). I can do this if I...
2
12398
by: mike | last post by:
Hi All I have a listbox which has a table as its row source. I want to be able to choose from this listbox (which has approximately 8 records) and have this value entered into another table (it currently has a field from this table as its control source but this doesn't seem to help). I am also having problems with retaining the value on the form - if I go back through the records on the form it will overwrite the previous values with...
3
6641
by: deko | last post by:
Is there any way to limit the number of records loaded into a ListBox? I looked at qdf.MaxRecords (to apply to the query that is the RowSource of the ListBox) but that only applies to ODBC data sources. I also looked at Tools > Options > Edit/Find and tried setting the "Don't display lists where more than this number of records read:" property, but that doesn't help. The List Box in question is supposed to allow scrolling/browsing of...
2
3422
by: Luca | last post by:
Hello, I'm using a windows form in which there is a standard ListBox control. I want to add/remove objects from the ArrayList associated to the ListBox, and I want the ListBox immediately shows graphically the change: e.g. if I remove an element from the ArrayList object, then that element should not be no more displayed in the list box. Actually i'm using this code below:
3
1756
by: Abra | last post by:
My C# application has a list (ListBox object), connected over a DataView to a dataset which corresponds to a table from a MySql database. I want to delete for example 4000-5000 rows from the table, which correspond to a certain filter. If I iterate the Rows from the table and check for each one the filter condition and, if true, I call the Delete() method, it takes several minutes till the respective rows are deleted. I tried also to...
8
2876
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in this listbox but I can't for the life of me figure out how to draw the control inside ListBox... I get as far as: private void lbImageList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
6
2767
by: gerbski | last post by:
Hi all, I am relatively new to ADO, but up to now I got things working the way I wanted. But now I've run into somethng really annoying. I am working in MS Access. I am using an Access frontend separately from a backend. The tables from the backend database are linked in the frontend database. In the frontend there is a Form with a listbox in it. The listbox rowsource is a query that selects all the records from a (linked)
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.