Solved

Checkbox with C#

Posted on 2014-04-08
3
208 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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