Display data in listbox from database SQL

Joined
Oct 17, 2010
Messages
3
Reaction score
0
Hi people,

I was about to display the data i retrieved from my database in a listbox. But my code doesn't work n i wish to have your advise on my mistake please.

- I have three column in my table (AttendanceTBL) - Event, Member, Status

- I have two combobox in my program. The first combobox select Event (Trip, Meeting), 2nd combobox select Status (Attend , Not Attend)

- I have a listbox as well. I wish to display member(s) name in a listbox based on the selection from the two combobox.

I have work out the coding. But i can't have the member name displayed when the page load. I tried googled for solution.. but i failed to get a right one. Below is my coding.

In the aspx.cs:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;


namespace AttendancPart
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            

            SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\AttendanceDB.mdf; Integrated Security=True;User Instance=True");
            SqlCommand cmd1 = new SqlCommand();
            cmd1.Connection = conn;
            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.CommandText = "GetMemberList";
            SqlParameter returnMember = new SqlParameter("@Member", SqlDbType.NVarChar, 20);
            SqlParameter selectedEvent = new SqlParameter("@Event", DropDownList2.Text);
            SqlParameter selectedStatus = new SqlParameter("@Status", DropDownList3.Text);
            returnMember.Direction = ParameterDirection.Output;
            cmd1.Parameters.Add(returnMember);
            cmd1.Parameters.Add(selectedEvent);
            cmd1.Parameters.Add(selectedStatus);
            conn.Open();
            cmd1.ExecuteNonQuery();
            conn.Close();
          
            ListBox1.Items.Add(Convert.ToString(returnMember.Value));
            
        }
     }
}


In the Procedures:

Code:
ALTER PROCEDURE dbo.GetMemberList
    
    (
    @Member nvarchar(20) OUTPUT,
    @Event nvarchar(50),
    @Status nvarchar(15)
    )
    
AS

    SELECT Member
    FROM AttendanceTBL
    WHERE Event = @Event AND @Status = Status

    RETURN

Thanks in advance for your advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top