public void GetTest() { _dt.Columns.Add("nullint", typeof(int)); _dt.Rows[0]["nullint"] = 333; DataTableReader reader = new DataTableReader(_dt); try { reader.Read(); int ordinal = reader.GetOrdinal("nullint"); // Get by name Assert.Equal(1, (int)reader["id"]); Assert.Equal(333, reader.GetInt32(ordinal)); Assert.Equal("Int32", reader.GetDataTypeName(ordinal)); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } }
public void GetTest() { dt.Columns.Add("nullint", typeof(int)); dt.Rows [0] ["nullint"] = 333; DataTableReader reader = new DataTableReader(dt); try { reader.Read(); int ordinal = reader.GetOrdinal("nullint"); // Get by name Assert.AreEqual(1, (int)reader ["id"], "#1 should be able to get by name"); Assert.AreEqual(333, reader.GetInt32(ordinal), "#2 should get int32"); Assert.AreEqual("System.Int32", reader.GetDataTypeName(ordinal), "#3 data type should match"); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } }
// <Snippet1> private static void TestGetTypeName() { DataTable table = GetCustomers(); using (DataTableReader reader = new DataTableReader(table)) { for (int i = 0; i < reader.FieldCount; i++) { Console.WriteLine("{0}: {1}", reader.GetName(i), reader.GetDataTypeName(i)); } } Console.WriteLine("Press Enter to finish."); Console.ReadLine(); }
public string GetDataTypeName(int i) { return(_reader.GetDataTypeName(i)); }
public void GetTest() { _dt.Columns.Add("nullint", typeof(int)); _dt.Rows[0]["nullint"] = 333; DataTableReader reader = new DataTableReader(_dt); try { reader.Read(); int ordinal = reader.GetOrdinal("nullint"); // Get by name Assert.Equal(1, (int)reader["id"]); Assert.Equal(333, reader.GetInt32(ordinal)); Assert.Equal("Int32", reader.GetDataTypeName(ordinal)); } finally { if (reader != null && !reader.IsClosed) reader.Close(); } }