表适配器返回不正确的结果
本文关键字:结果 不正确 返回 适配器 | 更新日期: 2023-09-27 18:26:41
我有一个应用程序,它接收csv文件并返回某些行。
获取csv并告诉要发送到数据库的数据的代码显示在这里
List<string[]> Results = sm.parseCSV2(ofd.FileName, de).Where(x=>x.Length >5).ToList();
foreach (string[] item2 in Results)
{
objSqlCommands.sqlCommandInsertorUpdate2("INSERT", Results);//laClient[0]);
}
这里有我的解析代码
public List<string[]> parseCSV2(string path, char[] delim)
{
// Intialise return value
List<string[]> parsedData = new List<string[]>();
try
{
// With 'StreamRader' read file that is located in save pat
using (StreamReader readFile = new StreamReader(path))
{
string line; // current line
string[] row; // array row
// Go thru file until we reach the end
while ((line = readFile.ReadLine()) != null)
{
row = line.Split(delim);// arry row equals values delimited by pipe
parsedData.Add(row); // add this to return value <List>
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return parsedData; // return list
}
在我的sql代码旁边
objConnections.executeSQL(connection,
"INSERT INTO generic.Client(ClientName) VALUES('" + text + "')");
然后我调用表适配器
//Refreshs the Client table on display from the
this.clientTableAdapter.Fill(this.CalcDataSet.Client);
//update the view
dgvClientlst.Update() ;
然而,返回的数据显示在下方
System.Collections.Generic.List`1[System.String[]]
有人建议我的查询实际上是在打印列表ToString(),但由于我的代码没有这样做,我不确定问题出在哪里。任何帮助都非常感谢
foreach (string[] item2 in Results)
{
objSqlCommands.sqlCommandInsertorUpdate2("INSERT", item2);//You were mixed up with Results here
}
我想你的代码可能是这样的(我不确定你的objSqlCommands.sqlCommandInsertorUpdate2
是否能处理传入的string[]
?)
foreach (string[] item2 in Results)
{
foreach(string item in item2)
objSqlCommands.sqlCommandInsertorUpdate2("INSERT", item);
}