I have a summary form used to display records in a database. I need to initiate some sort of reverse lookup for those columns that contain integer data so that the data is meaningful to the user.
For instance:
Say in the original form, that the user needed to choose a selection of users from a table.
code-behind:
if(!Page.IsPostBack)
{
SqlConnection Conn;
SqlCommand Cmd;
Conn = new SqlConnection("server=C099450d01;uid=sa;pwd=;database=tools");
Cmd = new SqlCommand("SELECT UID, LastName + ', ' + FirstName AS Name FROM Employee ORDER BY LastName", Conn);
//Creator
Conn.Open();
Creator.DataSource = Cmd.ExecuteReader();
Creator.DataTextField = "Name";
Creator.DataValueField = "UID";
Creator.DataBind();
Conn.Close();
}
//The summary Label Ctrl.
//Code-Behind to populate Ctrl:
SqlConnection Conn;
SqlCommand Cmd;
Conn = new SqlConnection("server=C099450D01;uid=sa;pwd=;database=tools");
Cmd = new SqlCommand("SELECT LastName, FirstName from Employee WHERE id = @uid", Conn);
Cmd.Parameters.Add("@uid", SqlDbType.Int).Value = Creator.SelectedItem.Value;
Conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
Label2.Text = dr.GetString(0) + " " + dr.GetString(1);
else
Label2.Text = "Not found.";
dr.Close();
The problem is that I get an error message saying that my connection is closed.
Can someone help me out with this.
Thanks alot!!
Tim