Home >Backend Development >C#.Net Tutorial >C# DataTable Usage Summary

C# DataTable Usage Summary

黄舟
黄舟Original
2017-02-20 11:04:551771browse

1. Create a new table

 private DataTable vsDt =new DataTable();

2. Clear the contents of the table (the columns in the table are still there)

vsDt.Clear();

3. Clear the columns of the table

vsDt.Columns.Clear();

4. Add columns to the table

vsDt.Columns.Add("BH", typeof(string));
vsDt.Columns.Add("RQ", typeof(string));

5. Add empty rows to the table

 DataRow vsDr = vsDt.NewRow();

If you have gone before adding a blank row N columns have been added to the table, so the newly added empty rows will also have these columns.
6. Add rows to the table

vsDt.Rows.Add(vsDr);

The above is the summary of C# DataTable usage. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn