下面是用于解析csv
文件并使用客户端和客户端名称填充 2X2 表的按钮的代码。我在网上查看过,但找不到合适的示例来说明我想做的事情,使用 VS 2012 和 C# 我想通读文件,只取出并插入客户端和客户端名称,但目前我的代码只需要一切文件内。
如果找到关键字,我的预期方法是csv
阅读并阅读它;使用它然后继续搜索,只是想知道是否有人可以告诉我如何?
例如,我想在laClient
列表中进行搜索,如果我发现HTY
我想在此之后获取接下来的 6 个字符并继续我的搜索。
private void btnUpload_Click(object sender, EventArgs e)
{
//Browse for file
OpenFileDialog ofd = new OpenFileDialog();
//Only show .csv files
ofd.Filter = "Microsoft Office Excel Comma Separated Values File|*.csv";
DialogResult result = ofd.ShowDialog();
//If the user selects a valid file
if (result == DialogResult.OK)
{
//File is delimited by a comma
char[] laClientDelim = { ',' };
//New object for string manipulation
objStringManipulation = new StringManipulation();
// Parse the csv file
List<string[]> lsClientList = objStringManipulation.parseCSV(ofd.FileName, laClientDelim);
foreach (string[] laClient in lsClientList)
{
//Create new object for manipulating the database
objSqlCommands = new SqlCommands("Client", "ClientName");
laClient[8].
//Inserts the client info into datbase
objSqlCommands.sqlCommandInsertorUpdate("INSERT", laClient[0]);
//Refreshs the Client table on display from the
this.clientTableAdapter.Fill(this.ImpDataSet.Client);
//update the view
dgvClientlst.Update();
}
}
}
csv 数据看起来像这样(下图),由于这个布局的质量很差,我试图附上一张图片以提高可读性,但我没有 10 名声望,所以我无法这样做。
ISBU,ShareName,Status,Share CCY,Benchmark,NAV Freq,CLASSCODE,SIMULATION,HEDGED,FUNDCCY
1,1,2,Cj0162289439,FGHT Global Funds - Asia incl Korea Equity,Activated,USD,Daily at 5:00pm (CVT),AC,n/a,N,,
2,1,2,Cj0622164928,FGHT Global Funds - Asia incl Korea Equity,Activated,USD,Daily at 5:00pm (CCT),ACEUR,n/a,N,,
3,1,2,Cj0212851702,FGHT Global Funds - Asia incl Korea Equity,Activated,USD,Daily at 5:00pm (CST),ACHEUR,n/a,Y,,
4,1,2,Cj0042850808,FGHT Global Funds - Asia incl Korea Equity,Activated,USD,Daily at 5:00pm (CET),AD,n/a,N,,
5,1,2,Cj0212851884,FGHT Global Funds - Asia incl Korea Equity,Activated,USD,Daily at 5:00pm (CDT),ADHEUR,n/a,Y,,
6,1,2,Cj0162849209,FGHT Global Funds - Asia incl Korea Equity,Activated,USD,Daily at 5:00pm (CHT),EC,n/a,N,,
7,1,2,Cj0622165065,FGHT Global Funds - Asia incl Korea Equity,未激活,美元,每日下午 5:00 (CET),ECEUR,n/a,N,,
8,1,2,Cj0112316214,FGHT Global Funds - Asia incl Korea Equity,Activated,USD,Daily at 5:00pm (CGT),ED,n/a,N,,
9,4,2,Cj0162193169,FGHT Global Funds - Asia incl Korea Equity,Activated,USD,Daily at 5:00pm (CBT),IC,n/a,N,,