The Art of Listening

February 20, 2008

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….emoticon… naa koy nasolve maski isa lang. hehe

Comments »

The URI to TrackBack this entry is: http://fma.blogsome.com/2008/02/20/d-flat-problem/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.


Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Minz Meyer