我正在将.txt
文件导入DataGridView
,现在效果相当不错。
不幸的是,唯一重要的值无法正确显示。
价值(德国追踪编号)为:“00340433914967320068”
请参阅随附的屏幕截图(第F2列)数据网格中的显示方式。 所有其他价值观都像魅力一样。
更长的像:"[x,xx] Gewicht<0>N^[0,00] DHL Paket<101>L^"
代码是:
private void buttonEasy1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textBox1.Text = openFileDialog1.FileName;
this.labeltxt1.Text = openFileDialog1.SafeFileName;
// .txt einlesen Anfang
string[] lines1 = { "[" + labeltxt1.Text + "]", "Format = Delimited(;)", "ColNameHeader = False "};
System.IO.File.WriteAllLines(@"C:\*\schema.ini", lines1);
string FileName1 = textBox1.Text;
OleDbConnection conn1 = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " +
Path.GetDirectoryName(FileName1) + ";Extended Properties='text;';");
conn1.Open();
OleDbDataAdapter adapter1 = new OleDbDataAdapter
("SELECT * FROM " + Path.GetFileName(FileName1), conn1);
DataSet ds1 = new DataSet("Temp");
adapter1.Fill(ds1);
conn1.Close();
dataGridView1.DataSource = ds1;
dataGridView1.DataMember = "Table";
// .txt einlesen Ende
答案 0 :(得分:0)
尝试更改DataGrid列格式。例如:
dataGridView1.Columns[1].DefaultCellStyle.Format = "N0";
或
dataGridView1.Columns[1].DefaultCellStyle.Format = "###################";
答案 1 :(得分:0)
有关史蒂夫评论的进一步信息 -
我尝试了这些解决方案:
How To Change DataType of a DataColumn in a DataTable?
DataTable dtCloned = dt.Clone();
dtCloned.Columns[1].DataType = typeof(String);
foreach (DataRow row in dt.Rows)
{
dtCloned.ImportRow(row);
}
和
adapter.FillSchema(table, SchemaType.Source);
table.Columns[1].DataType = typeof (String);
adapter.Fill(table);
没有变化 - 仍然显示3,40433191496732E + 17而不是00340433914967320587