EXIT CODE

Featured by

INTRODUCTION TO C#

Microsoft’s .NET and C# opens a whole New World of possibilities. There are many people in the industry, which see a great future to the .NE...

22/01/2018

Searching from a textbox

try
            {

                string Query = "select * from ellie_nhcpms.user;";
                MySqlCommand cmd = new MySqlCommand(Query, connection);
                connection.Open();
                DataSet ds = new DataSet();
                string commandString = "select * from ellie_nhcpms.user where username= '" + UserName.Text + "'";
                MySqlCommand sqlCmd = new MySqlCommand(commandString, connection);
                MySqlDataReader read = sqlCmd.ExecuteReader();


                if (read.Read() == true)
                {
                    lblhos.Text = read["hospitalname"].ToString();
                    label11.Text = read["empid"].ToString();

                   


                }
                else
                {
                    lblhos.Text = "";
                    label11.Text = "";

                  
                }

                                connection.Close();
            }

            catch (Exception)
            {
                //MessageBox.Show(es.Message);
            }

ExIT Codes in C#

if (MessageBox.Show(" Are you sure you want to Exit?", "closing session ?", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                //e.Cancel = true;  
            }
            else
            {
                btnexit.Focus();
           
                Application.Exit();
              
            }

C# login codes


Login Codes

try
            {
              

                MySqlCommand cmd = new MySqlCommand("Select * from k2sales.user where usertype=@usertype and username=@username and password=@password", connection);

                cmd.Parameters.AddWithValue("@usertype", comboBox1.Text);
                cmd.Parameters.AddWithValue("@username", UserName.Text);
                cmd.Parameters.AddWithValue("@password", Password.Text);
                connection.Open();
                MySqlDataAdapter adapt = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adapt.Fill(ds);
                connection.Close();
                int count = ds.Tables[0].Rows.Count;
                //If count is equal to 1, than show frmMain form
                if (count == 1)
                {
                    timer2.Start();
                    progressBar1.Show();
                    label7.Show();
                  

                }
                else
                {
                    label8.Show();
                    label10.Show();
                  
                    MessageBox.Show("  Login Failure..!!!! please select correct Usertype with corresponding username and password..thank you ", "login error!! ");
                }
            }

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