C #32 skills in development and use

Source: Internet
Author: User

1. How to customize the VC # DataGrid column title?

DataGridTableStyle dgts = new DataGridTableStyle ();

Dgts. MappingName = "myTable"; // myTable is the DataTable to load data.

  

DataGridTextBoxColumn dgcs = new DataGridTextBoxColumn ();

Dgcs. MappingName = "title_id ";

Dgcs. HeaderText = "title ID ";

Dgts. GridColumnStyles. Add (dgcs );

...

DataGrid1.TableStyles. Add (dgts );

2. How do I write the condition statements for retrieving all records whose fields are null?

... Where col_name is null

3. How do I receive the Enter key in the c # Winform application?

Set the form's AcceptButton.

4. For example, in Oracle NUMBER (15), what should I do in SQL Server?

NUMBER (15): use numeric and try it with a precision of 15.

5. How to Write the like statement Stored Procedure for SQL server applications?

Select * from mytable where haoma like '%' + @ hao + '%'

6. vc # In winform, how does one make textBox receive the carriage return key message (without buttons )?

Private void textBox1_KeyPress (object sender, System. Windows. Forms. KeyPressEventArgs e)

{

If (e. KeyChar! = (Char) 13)

Return;

Else

// Do something;

}

7. Why does the prompt that the conversion is invalid when (Int32) cmd. ExecuteScalar () is assigned to the Int32 variable?

Int32.Parse (cmd. ExecuteScalar (). ToString ());

8. How to add a column to the DataGrid of the child table as DataSource to display a field in the parent table?

Manually add a column to the table.

DataColumn dc = new DataColumn ("newCol", Type. GetType ("System. String "));

Dc. ExprEssion = "Parent. parentColumnName ";

Dt. Columns. Add (dc); // dt is a sub-table.

9. How to Make the DataGrid show only a certain part of the data of a column in the DataTable?

Select..., SUBSTR (string, start_index, end_index) as ***, *** from ***

10. How can I make the combobox of winform only available?

The DropDownStyle attribute determines whether the user can enter a new value in the text section and whether the list section is always displayed.

Value:

DropDown --- the text part can be edited. You must click the arrow to display the list.

DropDownList --- you cannot directly edit the text section. You must click the arrow to display the list.

Simple --- the text part can be edited. The list is visible.

11. How can I make the date displayed in the winform DataGrid show only the year, month, and day sections, and remove the time?

Add to_date (Date Field, yyyy-mm-dd) to the SQL statement)

12. How to merge the two columns of the database table into one column Fill into DataSet?

DcChehao = new DataColumn ("newColumnName", typeof (string ));

DcChehao. ExprEssion = "columnName1 + columnName2 ";

Dt. Columns. Add (dcChehao );

Oracle:

Select col1 | col2 from table

SQL server:

Select col1 + col2 from table

13. how to extract the text in parentheses from the merged fields as the display content of the DataGrid or other bound controls? Extract the text between the left and right brackets in the merged field content.

Select COL1, COL2, case

When COL3 like '% (%' THEN substr (COL3, INSTR (COL3, '(') + 1, INSTR (COL3, ')-INSTR (COL3, '(')-1)

End as COL3

From MY_TABLE

14. When you use the scroll wheel to browse the DataGrid data beyond a certain range, the DataGrid will lose the focus. How can this problem be solved?

This. Maid + = new MouseEventHandler (maid mousewheel );

Private void maid (object sender, MouseEventArgs e)

{

This. Maid ();

}

15. How can I change the '+' symbol entered by the keyboard to 'A '?

In the KeyPress event of textBox

If (e. KeyChar = +)

{

SendKeys. Send ("");

E. Handled = true;

}

16. How can I maximize the value of Winform when it is started?

This. WindowState = FormWindowState. Maximized;

17. c # How to get the current date and time? What is it in SQL statements?

C #: DateTime. Now

SQL server: GetDate ()

18. How to access a certain column in a row of the winform DataGrid or each column in each row?

DataGrid [row, col]

19. How to make a summary for the DataTable? For example, how many columns of the 'yanji 'column value of the DataTable?

Dt. Select ("city = Yanji"). Length;

20. After the DataGrid data is exported to Excel, 0212 and so on will change to 212. How can I export it and continue to display it as 0212?

Range. NumberFormat = "0000 ";

21.

① How to export data from the DataGrid to Excel for printing?

② Previously, TableStyle has been set for the DataGrid, that is, the column title and the column to be displayed have been customized. What should I do if I want to export data in a custom view?

③ After exporting data to Excel, how can I set a border for it?

④ How to align a column exported from DataGrid to Excel in the center?

⑤ After the data is exported from the DataGrid to Excel, how does one display the title row on each page during printing?

6. How can I achieve this when the data in the DataGrid is exported to Excel and the current page/total pages are displayed on each page?

Http://www.knowsky.com/csharp.asp

Private void button#click (object sender, System. EventArgs e)

{

Int row_index, col_index;

Row_index = 1;

Col_index = 1;

  

Excel. ApplicationClass excel = new Excel. ApplicationClass ();

Excel. Workbooks. Add (true );

  

DataTable dt = ds. Tables ["table"];

  

Foreach (DataColumn dcHeader in dt. Columns)

Related Article

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.