Work Assistant--c# 's DataTable implementation function
1) The user can choose to obtain information about all the courses that have been taken since admission: Course code, course name, course attributes, credits, scores, etc.
2) The user can choose to obtain the relevant information of a specific course: Course code, course name, course attributes, credits, scores, etc.
3) The user can obtain a weighted average (1 semesters, 1 academic year, all) within a specific time period.
Team members
13070003 Sail
13070046 Sun Yuchen
13070004 Cui Wei
13070006 Wang Nai
13070002 sheets of rain sail
13070045 Wang Tianmi
The DataTable of C #
The part that I am responsible for in the team project is the processing of the data. In particular, it is between the script and the graphical interface at the middle level of processing, that is, the script to fetch data from the academic administration and save in the local Excel, I am responsible for reading into the master program, and parse, and then, based on the GUI side incoming requests to filter the data and return to the graphical interface display, It also calculates the weighted average of the filtered data and returns it to the graphical interface display.
In the initial concept, I think the difficulty in the implementation process is the storage and management of the data, so I defined a structure in the original implementation version to store the results, the structure is as follows:
1 /// <summary>2 /// < results >structure, which contains data on the results of the climb down, respectively< academic year >,< semester >,< course name >,< course types >,< credits >,< performance points >,< results >Properties3 /// </summary>4 Public structGrades5 {6 Public stringAcademicyear;//academic year7 Public intsemester;//Semester8 Public stringCoursename;//Course Name9 PublicCoursetype Coursetype;//Course TypeTen Public DoubleCredit//credits One Public DoubleGPA;//Merit Points A Public stringGrade//grades, Categories: percentile scores and "pass", so defined as String - - /// <summary> the ///construction method with parameters - /// </summary> - /// <param name= "Academicyear" >academic year</param> - /// <param name= "semester" >Semester</param> + /// <param name= "Coursename" >Course Name</param> - /// <param name= "Coursetype" >Course Nature</param> + /// <param name= "credit" >credits</param> A /// <param name= "GPA" >Merit Points</param> at /// <param name= "Grade" >Achievements</param> - PublicGrades (stringAcademicyear,intSemester,stringCoursename, Coursetype Coursetype,DoubleCreditDoubleGpastringgrade) - { - This. Academicyear =academicyear; - This. Semester =semester; - This. Coursename =Coursename; in This. Coursetype =Coursetype; - This. Credit =Credit ; to This. GPA =GPA; + This. grade =grade; - } the}
But in the follow-up learning from excel in the process of reading data found a very useful class is the DataTable, he can easily implement the table class data management and operation, and even to implement functions such as query. So let's summarize the usage of the DataTable in the first blog post of the team project.
DataTable I think you can think of it as a sheet,datatable in Excel. Contains properties columns and rows, respectively, that represent a column and row, which can be thought of as a column and row in a sheet.
About DataTable
1) constructor function
A DataTable () Initializes a new instance of the DataTable class without parameters.
A DataTable (String tableName) Initializes a new instance of the DataTable class with the specified table name.
The DataTable (String TableName, String tablenamespace) Initializes a new instance of the DataTable class with the specified table name and namespace.
2) Common Properties
CaseSensitive indicates whether string comparisons in the table are case-sensitive.
ChildRelations gets the collection of child relationships for this DataTable.
Columns gets the collection of columns that belong to the table.
Constraints gets the collection of constraints maintained by the table.
The dataset gets the dataset to which this table belongs.
DefaultView gets a custom view of a table that might include a filtered view or cursor position.
HasErrors gets a value that indicates whether there is an error in any row of any table of the dataset to which the table belongs.
Minimumcapacity Gets or sets the initial starting size of the table. The initial starting size of the rows in the table. The default value is 50.
Rows gets the collection of rows that belong to the table.
TableName Gets or sets the name of the DataTable.
3) Common methods
AcceptChanges () submits all changes made to the table since the last call to AcceptChanges ().
BeginInit () begins initializing a DataTable that is used on a form or used by another component . Initialization occurs at run time.
Clone () cloningThe structure of the DataTable, including allDataTable Schemas and constraints.
Select () passes in a SQL-like statement, queries the data in the DataTable, and returns an array of query results as a DataRow
ImportRow (DataRow row) copies the DataRow into a DataTable, preserving any property settings as well as the initial and current values.
The merge (DataTable table) merges the specified DataTable with the current DataTable.
NewRow () creates a new DataRow with the same schema as the table .
Then attach the code that I use for the DataTable in C #:
1 //Initializing a DataTable2QueryResult =NewDataTable ();3QUERYRESULT.COLUMNS.ADD ("academic year",typeof(string));4QUERYRESULT.COLUMNS.ADD ("Semester",typeof(string));5QUERYRESULT.COLUMNS.ADD ("Course Name",typeof(string));6QUERYRESULT.COLUMNS.ADD ("Course Nature",typeof(string));7QUERYRESULT.COLUMNS.ADD ("credits",typeof(string));8QUERYRESULT.COLUMNS.ADD ("Merit Points",typeof(string));9QUERYRESULT.COLUMNS.ADD ("Achievements",typeof(string));Ten One //Get query Results ADataRow []tmpqureresult = Gradestable.select (queryString);
foreach (DataRow Dr in Tmpqureresult)
14QueryResult.Rows.Add (Dr. ItemArray);
In this case, the main use of the DataTable is the query operation, passing in the function in the QueryString, and then based on the QueryString query and return the result to an array of DataRow, and then add it to the returned result.
The DataTable of--c#, assistant to the big worker