473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.select 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.SELECT 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 SetUpDataBinding()

Dim datConn As String = "Integrated
Security=SSPI;Initial Catalog=DocsDates;Data Source=
(local)\vsdotnet"
Dim cnDocDates As New SqlConnection(datConn)

Try

Dim cmdGetCases As New SqlCommand
("CMasterSelectCommand", 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_due, comments from CaseDocs where
case_id in " & _
"(SELECT case_id from CaseMaster)",
cnDocDates)
Dim ds As New DataSet
daDocs.Fill(dsCases, "tblCaseDocs")
Session("dsCases") = dsCases

holdDte = Today
Catch ex As System.Data.SqlClient.SqlException

If
HttpContext.Current.Request.UserHostAddress = "129.0.0.5"
Then
Session("CurrentError") = ex.Message
Else
Session("CurrentError") = "Error
processing page."
End If
Server.Transfer("ApplicationError.aspx")
Finally
' cnDocDates.Close()
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.Select("doc_dte_due = '" &
holdDte.ToString & "'") ((( 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.DataBind() (((( Do I need this ? )))

End Sub

Nov 18 '05 #1
2 1438
ListBox1.DataBind() (((( 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_date" then you would not be allowed to use column1
you would have to use the "column_date" 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("dsCases")

//tell it which field you want to display in the listbox because it doesnt
know
ListBox1.DataTextField = "column_name_from_select_query"

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

//then tell it to display itself
ListBox1.DataBind()

--
Regards,
Alvin Bruney
Got Tidbits? Get it here
www.networkip.net/tidbits
"Gordon" <an*******@discussions.microsoft.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.select 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.SELECT 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 SetUpDataBinding()

Dim datConn As String = "Integrated
Security=SSPI;Initial Catalog=DocsDates;Data Source=
(local)\vsdotnet"
Dim cnDocDates As New SqlConnection(datConn)

Try

Dim cmdGetCases As New SqlCommand
("CMasterSelectCommand", 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_due, comments from CaseDocs where
case_id in " & _
"(SELECT case_id from CaseMaster)",
cnDocDates)
Dim ds As New DataSet
daDocs.Fill(dsCases, "tblCaseDocs")
Session("dsCases") = dsCases

holdDte = Today
Catch ex As System.Data.SqlClient.SqlException

If
HttpContext.Current.Request.UserHostAddress = "129.0.0.5"
Then
Session("CurrentError") = ex.Message
Else
Session("CurrentError") = "Error
processing page."
End If
Server.Transfer("ApplicationError.aspx")
Finally
' cnDocDates.Close()
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.Select("doc_dte_due = '" &
holdDte.ToString & "'") ((( 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.DataBind() (((( 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.select 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.SELECT 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 SetUpDataBinding()

Dim datConn As String = "Integrated
Security=SSPI;Initial Catalog=DocsDates;Data Source=
(local)\vsdotnet"
Dim cnDocDates As New SqlConnection(datConn)

Try

Dim cmdGetCases As New SqlCommand
("CMasterSelectCommand", 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_due, comments from CaseDocs where
case_id in " & _
"(SELECT case_id from CaseMaster)",
cnDocDates)
Dim ds As New DataSet
daDocs.Fill(dsCases, "tblCaseDocs")
Session("dsCases") = dsCases

holdDte = Today
Catch ex As System.Data.SqlClient.SqlException

If
HttpContext.Current.Request.UserHostAddress = "129.0.0.5"Then
Session("CurrentError") = ex.Message
Else
Session("CurrentError") = "Error
processing page."
End If
Server.Transfer("ApplicationError.aspx")
Finally
' cnDocDates.Close()
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.Select("doc_dte_due = '" &
holdDte.ToString & "'") ((( 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.DataBind() (((( 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
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...
3
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...
2
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...
2
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...
3
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...
2
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...
3
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,...
8
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...
6
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...

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.