Basic knowledge of C #

Source: Internet
Author: User

1. How do I get the form to center?
StartPosition set to Centerscreen

2. What are the benefits of not having a login form as a startup form in an application that has a login form?
1) When the main form is closed, you can exit the application directly;
2) The login form does not reside in memory for a long time.

3. How do I display another form in a multi-form application?
1) Create a (new) instance object variable to display the form;
2) Call the Show ()/showdialog () method of the instance object variable.

4. How do I display the login form before the Startup form (main form) is displayed?
1) in the Load event of the startup form, create a login form;
2) Call the ShowDialog () method of the Login form.

5. How do I get the return value from the dialog box form (the form shown by the ShowDialog () method)?
The DialogResult value of the dialog box form is.

6. How do I connect to an Access database?
1) using System.Data.OleDb; Link to Access database & SQL Database
Using System.Data.SqlClient; Link SQL Database
2) Set the parameters required to connect to the database
String constring =//Connection string (parameter string for linked database)
@ "Provider=Microsoft.Jet.OLEDB.4.0;" +
@ "Data Source=.\txl_db.mdb"; Disk database files
3) Create a Connection object variable
OleDbConnection con = new OleDbConnection ();
Con. ConnectionString = constring;
Con. Open ();

7. How to Query "Monkey King" is a legitimate user of the system?
1) Connect to the database
2) Define database Operations Command instance object variables
OleDbCommand cmd = new OleDbCommand ();
3) Set the connection object used by the command
Cmd. Connection = con;
4) Set the command content
Cmd.commandtext =
"Select" +
"Count (*)" +
"From" +
"[Tb_user]" +
"WHERE" +
"[Login name]= ' Monkey King ' and ' +
[Password]= ' Monkey King's password ';
Con. Open ();

5) Execute the query command and get the return value
int RecordCount = Convert.ToInt32 (cmd. ExecuteScalar ());
The return value is 1 o'clock, which indicates that there is a return value of 0 o'clock, indicating no.



Basic knowledge of C #

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.