实际上我正在使用 .CSV 文件。我已将 .CSV 文件的所有数据放入 DataTable 中。代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Revision1
{
public partial class Form1 : Form
{
DataTable datable = new DataTable();
public Form1()
{
InitializeComponent();
}
private void browsebtn_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Select .CSV ffile";
ofd.ShowDialog();
txtboxpath.Text = ofd.FileName;
}
private void operatebtn_Click(object sender, EventArgs e)
{
string filePath = txtboxpath.Text;
StreamReader sr = new StreamReader(filePath);
string line = sr.ReadLine();
string[] value = line.Split(',');
DataRow row;
foreach (string dc in value)
{
datable.Columns.Add(new DataColumn(dc));
}
while (!sr.EndOfStream)
{
value = sr.ReadLine().Split(',');
if (value.Length == datable.Columns.Count)
{
row = datable.NewRow();
row.ItemArray = value;
datable.Rows.Add(row);
}
}
}
private void generatecsvbtn_Click(object sender, EventArgs e)
{
}
}
}
到现在一切都很好。.CSV 文件的 google drive 链接点击 for.csv 文件
现在我正在检查以下条件,该条件也在最后一次 while 循环后的操作中:
DateTime dt = DateTime.ParseExact(datable.Rows[0][1].ToString(),"dd-MM-yy HH:ss", CultureInfo.InvariantCulture);
string s = dt.ToString();
string s1 = datable.Rows[0][1].ToString();
if(s==s1)
{
//code here
}
但是条件给出了错误的值。我如何修改我的代码以便条件为真?当我通过断点调试时,我得到以下值:
dt = 11/30/2017 10:00:00 AM
s = 30-NOV-2017 10:00:00 AM
s1 = 30-11-2017 10:00
皈依舞
qq_遁去的一_1
相关分类