I have a dataset contains 1 table where i want to iterate loop over the table.
Inside the loop i want to check if Column 1 is date type escape that column and move to next column.Please help me.
excelConnection = new OleDbConnection(connectionString);
//Get the name of First Sheet
excelConnection.Open();
excelSheet = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string sheetName = excelSheet.Rows[0]["TABLE_NAME"].ToString();
excelConnection.Close();
string query = "SELECT * FROM [" + sheetName + "]";
excelCommand = new OleDbCommand(query, excelConnection);
excelDataAdapter = new OleDbDataAdapter(excelCommand);
excelDataAdapter.Fill(excelData);
Thanks in advance.
foreach (DataColumn col in dt.Columns)
{
if (col.DataType == typeof(DateTime)) continue;
//Execute business logic for other columns
}
Try this code to get Datatype of Dataset table column:
if (Dataset1.Tables[0].Columns[1].ColumnName.ToLower().Contains("date") || Dataset1.Tables[0].Columns[1].DataType.ToString() == "System.DateTime")
{
//Do work;
}
Hope you like it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With