Write a DataTable to convert it into a string.
Copy codeThe Code is as follows:
Public static string DataTableToString (DataTable dt)
{
String dtstring = "";
For (int I = 0; I <dt. Columns. Count; I ++)
{
Dtstring = dtstring + dt. Columns [I]. ColumnName + "\ t ";
}
Dtstring = dtstring + "\ r \ n ";
For (int I = 0; I <dt. Rows. Count; I ++)
{
For (int j = 0; j <dt. Columns. Count; j ++)
{
Dtstring = dtstring + dt. Rows [I] [j] + "\ t ";
}
Dtstring = dtstring + "\ r \ n ";
}
Return dtstring;
}
It can be copied after it is changed to a string.
Copy codeThe Code is as follows:
String strTemp = DataTableToString (tt );
If (strTemp. Equals ("") // determines whether it is null.
Return;
Clipboard. Clear (); // Clear the content in the original Clipboard
Clipboard. SetText (strTemp); // Add text to the Clipboard and add Object-type data
Press Ctrl + V in a txt text to feel the feeling of victory :)