{"id":4710,"date":"2014-03-30T14:49:51","date_gmt":"2014-03-30T14:49:51","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-do-i-display-a-error-message-if-login-fail-for-windows-form-collection-of-common-programming-errors\/"},"modified":"2014-03-30T14:49:51","modified_gmt":"2014-03-30T14:49:51","slug":"how-do-i-display-a-error-message-if-login-fail-for-windows-form-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-do-i-display-a-error-message-if-login-fail-for-windows-form-collection-of-common-programming-errors\/","title":{"rendered":"How do I display a error message if login fail for windows form-Collection of common programming errors"},"content":{"rendered":"<p>I have a form with username, password and login button. I have three tables called doctor, nurse and admin.<\/p>\n<p>I want to display error message if login is unsuccessful when button is clicked.<\/p>\n<p>Below is my login button code. I tried putting in codes in the <code>catch (SqlException ex)<\/code> recommended by another person but it has no effect when the login button is pressed.<\/p>\n<pre><code>private void btnLogin_Click(object sender, EventArgs e)\n{\n    \/\/retrieve connection information info from App.config\n    string strConnectionString = ConfigurationManager.ConnectionStrings[\"sacpConnection\"].ConnectionString;\n    \/\/STEP 1: Create connection\n    SqlConnection myConnect = new SqlConnection(strConnectionString);\n    \/\/STEP 2: Create command\n    string strCommandtext = \"SELECT dUsername, dPassword from DOCTOR\";\n    \/\/ Add a WHERE Clause to SQL statement\n    strCommandtext += \" WHERE dUsername=@dname AND dPassword=@dpwd;\";\n    strCommandtext += \"SELECT nUsername, nPassword from NURSE WHERE nUsername=@nname AND nPassword=@npwd;\";\n    strCommandtext += \"SELECT windowsUsername, windowsPassword from WINDOWSADMIN WHERE windowsUsername=@aname AND windowsPassword=@apwd\";\n    SqlCommand cmd = new SqlCommand(strCommandtext, myConnect);\n    cmd.Parameters.AddWithValue(\"@dname\", textUsername.Text);\n    cmd.Parameters.AddWithValue(\"@dpwd\", txtPassword.Text);\n    cmd.Parameters.AddWithValue(\"@nname\", textUsername.Text);\n    cmd.Parameters.AddWithValue(\"@npwd\", txtPassword.Text);\n    cmd.Parameters.AddWithValue(\"@aname\", textUsername.Text);\n    cmd.Parameters.AddWithValue(\"@apwd\", txtPassword.Text);\n\n\n    try\n    {\n        \/\/ STEP 3: open connection and retrieve data by calling ExecuteReader\n        myConnect.Open();\n        \/\/ STEP 4: Access Data\n        SqlDataReader reader = cmd.ExecuteReader();\n\n\n        while (reader.Read()) \/\/For Doctor\n        {\n            if (MessageBox.Show(\"Login Successful\") == DialogResult.OK)\n            {\n                timer1.Enabled = true;\n            } \n        } \n        reader.NextResult();\n        while (reader.Read()) \/\/For Nurse\n        {\n            if (MessageBox.Show(\"Login Successful\") == DialogResult.OK)\n            {\n                timer2.Enabled = true;\n            }\n        }\n\n        reader.NextResult();\n        while (reader.Read()) \/\/For Admin\n        {\n            if (MessageBox.Show(\"Login Successful\") == DialogResult.OK)\n            {\n                timer3.Enabled = true;\n            }\n        }\n\n\n\n        \/\/STEP 5: close connection\n        reader.Close();\n    }\n    catch (SqlException ex)\n    {\n        string message = ex.Message;\n        string caption = \"Error Detected in Input\";\n        MessageBoxButtons buttons = MessageBoxButtons.YesNo;\n        DialogResult result;\n\n        \/\/ Displays the MessageBox.\n\n        result = MessageBox.Show(message, caption, buttons);\n    }\n    finally\n    {\n        \/\/STEP 5: close connection\n        myConnect.Close();\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a form with username, password and login button. I have three tables called doctor, nurse and admin. I want to display error message if login is unsuccessful when button is clicked. Below is my login button code. I tried putting in codes in the catch (SqlException ex) recommended by another person but it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4710","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4710"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4710\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}