Solved

Checkbox with C#

Posted on 2014-04-08
3
203 Views
Last Modified: 2014-04-08
Hi all ,

I have some table that look like ( see screenshot) also I attached the application.

I would like to display in my app just the rows with the false result in column "Closed".

Here is my combobox code:

//combobox lastname display in the textboxs
        private void comboLname_SelectedIndexChanged(object sender, EventArgs e)
        {
            string conn = "Data Source=srv-db-02;Initial Catalog=RMSCRM;Persist Security Info=True;User ID=test;Password=masterB4";
            string Query = "select * from RMSCRM.dbo.sales where LastName= '" + comboLname.Text + "' ;";


            SqlConnection Myconn = new SqlConnection(conn);
            SqlCommand cmdDataBase = new SqlCommand(Query, Myconn);
            SqlDataReader Reader;
            try
            {
                Myconn.Open();
                Reader = cmdDataBase.ExecuteReader();
                if (Reader.Read())
                {
                    string ID = Reader.GetInt32(Reader.GetOrdinal("ID")).ToString();
                    string AccountNuber = Reader.GetString(Reader.GetOrdinal("AccountNumber")).ToString();
                    string Time = Reader.GetDateTime(Reader.GetOrdinal("Time")).ToString();
                    string Deposit = Reader.GetDecimal(Reader.GetOrdinal("Deposit")).ToString();
                    string slastname = Reader.GetString(Reader.GetOrdinal("lastname"));
                    string sname = Reader.GetString(Reader.GetOrdinal("name"));
                    string semail = Reader.GetString(Reader.GetOrdinal("emailaddress"));
                    bool scheck = Reader.GetBoolean(Reader.GetOrdinal("closed"));
                    int statusIndex = Reader.GetOrdinal("status");
                    string sstatus = Reader.IsDBNull(statusIndex) ? null : Reader.GetString(statusIndex);
                    int noteIndex = Reader.GetOrdinal("Note");
                    string snote = Reader.IsDBNull(noteIndex) ? null : Reader.GetString(noteIndex);
                    //int historyIndex = Reader.GetOrdinal("history");
                    //string slbox = Reader.IsDBNull(historyIndex) ? null : Reader.GetString(historyIndex);

                 
             

            

                    txtid.Text = ID;
                    txtacnum.Text = AccountNuber;
                    txttime.Text = Time;
                    txtdeposit.Text = Deposit;
                    txtlname.Text = slastname;
                    txtStatus.Text = sstatus;
                    txtNote.Text = snote;
                    txtName.Text = sname;
                    txtEmail.Text = semail;
                    checkBox1.Checked = scheck;

                    
                    
                    
                    
                    
                    //close reader ready for our next query
                    Reader.Close();
                    cmdDataBase.CommandText = "SELECT * FROM History WHERE SalesID=@SalesID";


                    //add parameter to salesID
                    cmdDataBase.Parameters.Clear();
                    cmdDataBase.Parameters.AddWithValue("@SalesID", ID);

                    Reader = cmdDataBase.ExecuteReader();

                    //cleare and repopulate listbox
                    listBox1.Items.Clear();

                    while (Reader.Read())
                    {
                        listBox1.Items.Add(Reader.GetString(Reader.GetOrdinal("History")));
                    }

      

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Myconn.Close();
            }
        }

Open in new window

Capture.JPG
data.JPG
0
Comment
Question by:Moti Mashiah
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39987406
The easiest way would be to filter them at source:
string Query = "select * from RMSCRM.dbo.sales where LastName= '" + comboLname.Text + "' and Closed=0;";

Open in new window

0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39987445
That's perfect Thank you again Carl.

I hope that one day I will be able to figure all these things by myself LOL...
0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 39987447
Great as always
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now