Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 21st, 2004, 03:57 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default multiple reading from db

Hi.. im kinda new on using asp.net. need great help here.
currently im doing the listbox where by the user can multi select the information e.g(Class A). than the information from (Class A) e.g(student's mobile number) will be shown on the textbox. currently i could only display 1 number. any idea to solve my problem? thanks!

Private Sub listbox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox.SelectedIndexChanged
        Dim sql, dbcomm, dbread
        Dim dbcon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Inetpub\wwwroot\fyr project\bin\DESIGNATION.mdb;")
        sql = "SELECT mobile_num FROM STUDENT WHERE pem_grp = '" & listbox.SelectedItem.Text & "' "
        dbcomm = New OleDbCommand(sql, dbcon)
        Dim reader As OleDbDataReader

        Try

            dbcon.Open()
            reader = dbcomm.ExecuteReader()
            reader.Read()

            smsTo.Text = reader("mobile_num")
            smsTo.Text += "@gSMS, "
            smsTo.Text += reader("mobile_num")
            reader.Close()

        Catch ex As Exception
        Finally
            If (Not dbcon Is Nothing) Then
                dbcon.Close()
            End If
        End Try
    End Sub

 
Old October 22nd, 2004, 07:56 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi mate,

 I'm new too so maybe this isn't the best way or totally
 correct but i think...

  your SQL query will only give you the first selected item of
  your listbox.

   sql = "SELECT mobile_num FROM STUDENT WHERE pem_grp = '" &
         listbox.SelectedItem.Text & "' "

  you could rewrite your SQL query to be something like:

  "select the mobile_num from student where pem_grp in 'string1',
   'string2', 'string3' " etc (checkout the 'in' syntax under SQL
   select statements)

  this would select records where pem_grp was values 'string1',
  'string2' or 'string3'. You would have to write some code to
  build this 'on-the-fly' depending on how your user ticked the
  listbox selections.

  As far as manipulating the records once you've selected them, I
  would read you records into a dataset. You can then loop through
  the dataset looking at various records and take action
  accordingly:

    eg
    dim aTotalSmiths as integer = 0
    for i = 0 to myDataset.tables("mytable").rows.count-1
     if myDataset.tables("mytable").rows(i).item("name")=" smith" then
        aTotalSmiths += 1
     end if
    next

    the above loops through the dataset counting up all guys whose
    name is 'smith'. you could also change the datafield eg

     if myDataset.tables("mytable").rows(i).item("name")=" smith" then
        myDataset.tables("mytable").rows(i).item("name") = "Mr Smith"
     end if

  Hope some of this helps. If its too dumb then apologies.
  If someone else knows a better way then I wont be offended.
  Best of luck
  Chas. (Canterbury, UK)


 
Old October 23rd, 2004, 08:24 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that will be a great help for me. thanks alot!






Similar Threads
Thread Thread Starter Forum Replies Last Post
reading text between multiple delimitters using c# marker Visual Studio 2005 0 May 28th, 2007 08:10 AM
Reading multiple txt from a specified dir diegoblin Beginning VB 6 3 November 20th, 2006 06:54 PM
Reading multiple lines as a single unit ravishakya Pro Java 0 September 14th, 2006 09:08 AM
Capturing\Reading File Contents into DB with PHP aingalsbe PHP How-To 2 December 30th, 2005 09:48 AM
multiple reading from db dannyphw Classic ASP Databases 2 October 21st, 2004 11:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.