private static DataTable CreateNumbersTable()
{
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
DataTable table = new DataTable("Numbers");
table.Columns.Add("number", typeof(int));
foreach (int n in numbers)
{
table.Rows.Add(new object[] { n });
}
return table;
}
private static DataTable CreateEmptyNumbersTable()
{
DataTable table = new DataTable("EmptyNumbers");
table.Columns.Add("number", typeof(int));
return table;
}
private static DataTable CreateDigitsTable()
{
string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
DataTable table = new DataTable("Digits");
table.Columns.Add("digit", typeof(string));
foreach (string digit in digits)
{
table.Rows.Add(new object[] { digit });
}
return table;
}
private static DataTable CreateWordsTable()
{
string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };
DataTable table = new DataTable("Words");
table.Columns.Add("word", typeof(string));
foreach (string word in words)
{
table.Rows.Add(new object[] { word });
}
return table;
}
private static DataTable CreateWords2Table()
{
string[] words = { "believe", "relief", "receipt", "field" };
DataTable table = new DataTable("Words2");
table.Columns.Add("word", typeof(string));
foreach (string word in words)
{
table.Rows.Add(new object[] { word });
}
return table;
}
private static DataTable CreateWords3Table()
{
string[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" };
DataTable table = new DataTable("Words3");
table.Columns.Add("word", typeof(string));
foreach (string word in words)
{
table.Rows.Add(new object[] { word });
}
return table;
}
private static DataTable CreateWords4Table()
{
string[] words = { "blueberry", "chimpanzee", "abacus", "banana", "apple", "cheese" };
DataTable table = new DataTable("Words4");
table.Columns.Add("word", typeof(string));
foreach (string word in words)
{
table.Rows.Add(new object[] { word });
}
return table;
}
private static DataTable CreateAnagramsTable()
{
string[] anagrams = { "from ", " salt", " earn ", " last ", " near ", " form " };
DataTable table = new DataTable("Anagrams");
table.Columns.Add("anagram", typeof(string));
foreach (string word in anagrams)
{
table.Rows.Add(new object[] { word });
}
return table;
}
private static DataTable CreateScoreRecordsTable()
{
var scoreRecords = new[] { new {Name = "Alice", Score = 50},
new {Name = "Bob" , Score = 40},
new {Name = "Cathy", Score = 45}
};
DataTable table = new DataTable("ScoreRecords");
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Score", typeof(int));
foreach (var r in scoreRecords)
{
table.Rows.Add(new object[] { r.Name, r.Score });
}
return table;
}
private static DataTable CreateAttemptedWithdrawalsTable()
{
int[] attemptedWithdrawals = { 20, 10, 40, 50, 10, 70, 30 };
DataTable table = new DataTable("AttemptedWithdrawals");
table.Columns.Add("withdrawal", typeof(int));
foreach (var r in attemptedWithdrawals)
{
table.Rows.Add(new object[] { r });
}
return table;
}
private static DataTable CreateNumbersATable()
{
int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
DataTable table = new DataTable("NumbersA");
table.Columns.Add("number", typeof(int));
foreach (int number in numbersA)
{
table.Rows.Add(new object[] { number });
}
return table;
}
private static DataTable CreateNumbersBTable()
{
int[] numbersB = { 1, 3, 5, 7, 8 };
DataTable table = new DataTable("NumbersB");
table.Columns.Add("number", typeof(int));
foreach (int number in numbersB)
{
table.Rows.Add(new object[] { number });
}
return table;
}
private static DataTable CreateLowNumbersTable()
{
int[] lowNumbers = { 1, 11, 3, 19, 41, 65, 19 };
DataTable table = new DataTable("LowNumbers");
table.Columns.Add("number", typeof(int));
foreach (int number in lowNumbers)
{
table.Rows.Add(new object[] { number });
}
return table;
}
private static DataTable CreateFactorsOf300()
{
int[] factorsOf300 = { 2, 2, 3, 5, 5 };
DataTable table = new DataTable("FactorsOf300");
table.Columns.Add("factor", typeof(int));
foreach (int factor in factorsOf300)
{
table.Rows.Add(new object[] { factor });
}
return table;
}
private static DataTable CreateDoublesTable()
{
double[] doubles = { 1.7, 2.3, 1.9, 4.1, 2.9 };
DataTable table = new DataTable("Doubles");
table.Columns.Add("double", typeof(double));
foreach (double d in doubles)
{
table.Rows.Add(new object[] { d });
}
return table;
}
private static DataTable CreateEmployees1Table()
{
DataTable table = new DataTable("Employees1");
table.Columns.Add("id", typeof(int));
table.Columns.Add("name", typeof(string));
table.Columns.Add("worklevel", typeof(int));
table.Rows.Add(new object[] { 1, "Jones", 5 });
table.Rows.Add(new object[] { 2, "Smith", 5 });
table.Rows.Add(new object[] { 2, "Smith", 5 });
table.Rows.Add(new object[] { 3, "Smith", 6 });
table.Rows.Add(new object[] { 4, "Arthur", 11 });
table.Rows.Add(new object[] { 5, "Arthur", 12 });
return table;
}
private static DataTable CreateEmployees2Table()
{
DataTable table = new DataTable("Employees2");
table.Columns.Add("id", typeof(int));
table.Columns.Add("lastname", typeof(string));
table.Columns.Add("level", typeof(int));
table.Rows.Add(new object[] { 1, "Jones", 10 });
table.Rows.Add(new object[] { 2, "Jagger", 5 });
table.Rows.Add(new object[] { 3, "Thomas", 6 });
table.Rows.Add(new object[] { 4, "Collins", 11 });
table.Rows.Add(new object[] { 4, "Collins", 12 });
table.Rows.Add(new object[] { 5, "Arthur", 12 });
return table;
}
创建DataTable
最新推荐文章于 2023-07-03 11:22:19 发布