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:
In the Procedures:
Thanks in advance for your advice.
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.