using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using System.Text;
namespace SDM
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void browsefiles_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog()==DialogResult.OK)
{
display(openFileDialog1.FileName);
}
}
private void display(string text)
{
textBox1.Text = string.Format("{0}", openFileDialog1.FileName);
}
private void importFile_Click(object sender, EventArgs e)
{
string PathConn = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox1.Text + "; Jet OLEDB:Engine Type=5;Extended Properties=\"Excel 12.0;\"");
OleDbConnection conn= new OleDbConnection(PathConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select * from [" + textBox2.Text+ "$]", conn);
DataTable dt = new DataTable();
myDataAdapter.Fill(dt);
if (textBox2.Text.Contains("Life Group"))
{
dt.Columns.Add("Agent Code", typeof(string));
}
else if (textBox2.Text.Contains("Life Individual"))
{
DataColumn col = dt.Columns[9].ToString();
String.Format("####-###");
Console.WriteLine(col);
myDataAdapter.Fill(dt);
}
我正在尝试将Column [9]的格式从“1234567”更改为“1234-567”。我只是想在第4个数字之后添加一个短划线,但是在调用整个列进行更改时遇到了问题。任何人都可以提出任何建议吗?非常感谢。