【发布时间】:2019-09-13 14:16:44
【问题描述】:
我正在从 excel 中读取值并将其存储在 Datagridview 中。数据表的第一列是日期,我需要 mm/dd/yyyy 格式,但它显示 mm/dd/yyyy 12:00:00 AM。我只需要日期部分。
我尝试过使用 defaultcellstyle.Format 和许多其他方法,但我没有找到解决方案
OleDbConnection connection = new OleDbConnection(connectionstring);
OleDbCommand command = new OleDbCommand("Select * From [POSFailures$] WHERE Date =@param1", connection);
command.Parameters.Add(new OleDbParameter("param1", todaydate));
command.Connection = connection;
try
{
connection.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(command);
sda.Fill(dtexcel2);
connection.Close();
}
catch (Exception)
{
}
return dtexcel2;
}
我已经尝试使用 for 循环和 google 中提到的所有内容,但我仍然没有得到想要的结果。任何解决方案都会有很大帮助!
【问题讨论】:
-
您可以在使用 DefaultCellStyle.Format 后发布 DataGridView 的屏幕截图吗?我也没有在任何地方的代码中看到这一点。它还包含时间吗?
-
在 format 属性之后,我仍然没有得到想要的格式
-
我在任何地方都看不到您的格式代码。您可以在 DataGridView 上设置格式的位置发布代码吗?
-
而且我没有在数据网格中添加任何列,因为我使用的是 excel 中的标题
-
发布你的代码,我没有看到你在任何地方设置 DefaultCellStyle.Format = "MM/dd/yyyy" !如果您不告诉它您想要的格式,您如何期望它格式化?请发布代码。
标签: c# excel datagridview datatable