C # Development and application skills

Source: Internet
Author: User

1. How to customize Vc#datagrid column headings?

DataGridTableStyle Dgts = new DataGridTableStyle ();
Dgts. MappingName = "MyTable"; MyTable for 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. Retrieve a conditional statement for all records that have a blank field?
. where col_name is null

3. How to receive return enter input in C # WinForm application?
Set the AcceptButton of the form.

4. For example, number (15) in Oracle, what should it be in SQL Server?
Number (15): Use numeric, Precision 15 try.

5.sql server How do I write a stored procedure that uses the like statement?
SELECT * FROM mytable where haoma like '% ' + @hao + '% '

How to let the TextBox accept the ENTER key message in the 6.vc# WinForm (without a button)?
private void Textbox1_keypress (object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (E.keychar!= (char) 13)
Return
Else
Do something;
}

7. Why (Int32) cmd. ExecuteScalar () when assigning to a Int32 variable, the prompt conversion is invalid?
Int32.Parse (cmd. ExecuteScalar (). ToString ());

8.DataSource How do I add a column to the DataGrid in the child table to display a field in the master table?
Manually add a column to the child table.
DataColumn dc = new DataColumn ("Newcol", Type.GetType ("System.String"));
dc. Expression = "Parent.parentcolumnname";
Dt. Columns.Add (DC); DT to child table

9. How do I make the DataGrid display only one part of the data in a DataTable?
Select ..., SUBSTR (String, Start_index, End_index) as * * *, * * * * FROM * * *

10. How to make the WinForm ComboBox can only choose not to input?
The DropDownStyle property determines whether the user can enter a new value in the text section and the list part is always displayed.
Value:
The DropDown---text section can be edited. The user must click the arrow button to display the list section.
DropDownList---Users cannot edit the text section directly. The user must click the arrow button to display the list section.
The simple---text section can be edited. The list section is always visible.

11. How to make the date displayed in the DataGrid of WinForm only show the month and day part, take out the time?
SQL statement plus to_date (date field, ' Yyyy-mm-dd ')

12. How to combine two columns of a database table into one column fill into a 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 do you extract the bracketed text from the merged field as a display for a DataGrid or other bound control? That is, the text between the left parenthesis (and the closing parenthesis) in the merged field contents is extracted.
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. The DataGrid loses focus when browsing the DataGrid data with the mouse wheel over a certain range. How to solve?
This.datagrid1.mousewheel+=new MouseEventHandler (Datagrid1_mousewheel);
private void Datagrid1_mousewheel (object sender, MouseEventArgs e)
{
This.dataGrid1.Select ();
}

15. How to make keyboard input ' + ' symbol into ' A '?
In the KeyPress event of the textbox
if (E.keychar = = ' + ')
{
Sendkeys.send ("A");
E.handled = true;
}

16. How to maximize the WinForm when starting?

This. WindowState = formwindowstate.maximized;

17.c# how to get the current date and time, what is in the SQL statement?

C #: DateTime.Now

SQL Server:getdate ()

18. How do I access a column of a row in the WinForm DataGrid, or each row of columns?

Datagrid[row,col]

19. How to summarize the DataTable, such as the column value of the DataTable ' Yanji '?

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

20.DataGrid data exported to Excel 0212 will become 212. How do I make it export and continue to display 0212?

Range. NumberFormat = "0000";

21st.

How do ① export DataGrid data to Excel for printing?

② has previously set TableStyle for the DataGrid, that is, customizing the column headings and the columns to be displayed, what if you want to export the data in a custom view?

③ you export data to Excel, how do you set a border for it?

④ How do I align a column that is exported from the DataGrid to Excel?

When ⑤ data is exported from the DataGrid to Excel, how do I make the header row appear on each page when printed?

⑥datagrid data is exported to Excel, each page displays ' current page/page ', how to achieve it?

①

private void Button1_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)

Excel. Cells[row_index, col_index++] = dcheader.columnname;

foreach (DataRow dr in Dt. Rows)

{

Col_index = 0;

foreach (DataColumn dc in dt. Columns)

{

Excel. Cells[row_index+1, col_index+1] = DR[DC];

col_index++;

}

row_index++;

}

Excel. Visible = true;

}

private void Form1_Load (object sender, System.EventArgs e)

{

SqlConnection conn = new SqlConnection ("server=tao;uid=sa;pwd=;d atabase=pubs");

Conn. Open ();

SqlDataAdapter da = new SqlDataAdapter ("select * FROM authors", Conn);

ds = new DataSet ();

Da. Fill (ds, "table");

DataGrid1.DataSource = ds;

DataGrid1.DataMember = "Table";

}

②datagrid1.tablestyles[0]. Gridcolumnstyles[index]. Headertext;//index can be from 0~datagrid1.tablestyles[0]. Gridcolumnstyles.count traversal.

③excel.range Range;

Range=worksheet.get_range (worksheet. Cells[1,1],xst.cells[ds. Tables[0]. Rows.count+1,ds. Tables[0]. Columns.count]);

Range. Borderaround (Excel.xllinestyle.xlcontinuous,excel.xlborderweight.xlthin, Excel.xlcolorindex.xlcolorindexautomatic,null);

Range. Borders[excel.xlbordersindex.xlinsidehorizontal]. ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic;

Range. Borders[excel.xlbordersindex.xlinsidehorizontal]. LineStyle =excel.xllinestyle.xlcontinuous;

Range. Borders[excel.xlbordersindex.xlinsidehorizontal]. Weight =excel.xlborderweight.xlthin;

Range. Borders[excel.xlbordersindex.xlinsidevertical]. ColorIndex =excel.xlcolorindex.xlcolorindexautomatic;

Range. Borders[excel.xlbordersindex.xlinsidevertical]. LineStyle = Excel.XlLineStyle.xlContinuous;

Range. Borders[excel.xlbordersindex.xlinsidevertical]. Weight = Excel.XlBorderWeight.xlThin;

④range. HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter

⑤worksheet. Pagesetup.printtitlerows = "$1:$1";

⑥worksheet. Pagesetup.centerfooter = "&p page/Total &n page";

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.