D flat problem….
I have solved a problem in D flat. The problem is how to output the record into a combobox and label. well here it is:
In a general decleration:
SqlConnection con;
SqlCommand com;
SqlDataAdapter adapter;
SqlDataReader reader;
In a load function:
string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (con = new SqlConnection(cs))
{
con.Open();
com = new SqlCommand("SELECT lname + ‘, ‘+fname As fullname, id FROM Employee Order By lname Asc",con);
adapter = new SqlDataAdapter(com);
adapter.Fill(dataSet1,"Employee");
comboBox1.DataSource = dataSet1.Tables["Employee"];
comboBox1.ValueMember = "fullname";
reader = com.ExecuteReader();
reader.Read();
label1.Text = reader[1].ToString();
con.Close();
}
In the combobox SelectionChangeCommitted event
string a;
string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (con = new SqlConnection(cs))
{
con.Open();
a = comboBox1.SelectedItem.ToString();
com = new SqlCommand("SELECT id FROM Employee Where lname+’, ‘+fname=@fullname", con);
com.Parameters.AddWithValue("@fullname", comboBox1.SelectedValue);
reader = com.ExecuteReader();
while (reader.Read())
{
label1.Text = reader[0].ToString();
}
con.Close();
}




hehe….
… naa koy nasolve maski isa lang. hehe

