C # do landing interface

Source: Internet
Author: User

Landing interface is the most important is the database access, here is not much about the interface design,

Directly to the code: (This code is added to the event of the login button)

#region Defining user Information variables
String UserName = TextBox_User_Name.Text.Trim ();
String userpassword = TextBox_User_Password.Text.Trim ();
#endregion
#region Check if the user has entered user information
if (UserName = = "" && UserPassword = = "")
{
MessageBox.Show ("You haven't entered user information yet!") "," Prompt! ", MessageBoxButtons.OK, messageboxicon.exclamation);
Return
}
if (UserName = = "")
{
MessageBox.Show ("You haven't entered a user name yet!") "," Prompt! ", MessageBoxButtons.OK, messageboxicon.exclamation);
Return
}
if (UserPassword = = "")
{
MessageBox.Show ("You haven't entered a user password yet!") "," Prompt! ", MessageBoxButtons.OK, messageboxicon.exclamation);
Return
}
#endregion
#region Check that the information entered by the user is legitimate
BOOL Is_user_name_ok = (username.contains ("\ \") | | Username.contains ("\" ") | | Username.contains ("\ '"));
if (IS_USER_NAME_OK)
{
MessageBox.Show ("The user name you entered contains special characters: \R1: English quotation marks (\", ') \R2: English backslash (\ \)! "," Prompt! ", MessageBoxButtons.OK, messageboxicon.exclamation);
Return
}
BOOL Is_user_password_ok = (userpassword.contains ("\ \") | | Userpassword.contains ("\" ") | | Userpassword.contains ("\ '"));
if (IS_USER_PASSWORD_OK)
{
MessageBox.Show ("The user password you entered contains special characters: \R1: English quotation marks (\", ') \R2: English backslash (\ \)! "," Prompt! ", MessageBoxButtons.OK, messageboxicon.exclamation);
Return
}
#endregion

#region Database access

string conn_string = "";
conn_string = "Data source= ' Database.mdb '; provider=microsoft.ace.oledb.12.0; ";
OleDbConnection db_conn = new OleDbConnection (conn_string);
Db_conn.open ();

oledbcommand db_cmd = new OleDbCommand ("SELECT * from [User] where username= '" + Usernam E + "' and userpassword= '" + userpassword_ + "'", db_conn );
                OleDbDataReader db_reader = Db_cmd.executereader ();
                db_reader.read ();

if (! Db_reader. HasRows)
{
MessageBox.Show ("User name or password is wrong! "," Error! ", MessageBoxButtons.OK, messageboxicon.warning);
Return
}
Else
{
//code to execute after successful login
}

#endregion

Finish

Note:

The code gives the code to check if the user has entered a specification that the information has entered.

Precautions:

1: Here the database path (data Source) has the database driver (Provider) is the author of the computer, please change your own, Windows7 comes with microsoft.ace.oledb.12.0; By the way, a low version of provider cannot open a high-level database.

2: The data table in the query statement has queried the field to be modified by the reader.

3: The code here is for access, and the SQL reader needs to change OLE DB to SQL. (Case sensitive)

4: The name of the control inside may be different from that of the reader, but most of them understand it, just change it.

Please pay attention to the above precautions, but do not blame the author, these are must be noted.

For source code readers please send a request to: [Email protected]

C # do landing interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.