C# 在x数量¦之后向SQL发送数据;线

C# 在x数量¦之后向SQL发送数据;线,c#,sql,ado.net,C#,Sql,Ado.net,我是C#新手,我想知道是否可以在文本行中的7个左右管道字符(“|”)之后将数据发送到sql 我目前有以下几点 // Read each line of the file into a string array. Each element of the array is one line of the file. string[] lines = System.IO.File.ReadAllLines(@"C:\WatchFolder\WriteLines2.txt"); // Display

我是C#新手,我想知道是否可以在文本行中的7个左右管道字符(
“|”
)之后将数据发送到sql

我目前有以下几点

// Read each line of the file into a string array. Each element of the array is one line of the file.
string[] lines = System.IO.File.ReadAllLines(@"C:\WatchFolder\WriteLines2.txt");

// Display the file contents by using a foreach loop.

int count = 0;

char[] splitchar = { '|' };
System.Console.WriteLine("Contents of WriteLines2.txt = ");
foreach (string line in lines)
{
    string[] strArr = null;

    strArr = line.Split(splitchar);
    int iLen = strArr.Length - 1;
    for (count = 0; count <= iLen; count++)
    {
        Console.WriteLine(strArr[count]);
    }

}

// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
//将文件的每一行读入字符串数组。数组的每个元素都是文件的一行。
string[]lines=System.IO.File.ReadAllLines(@“C:\WatchFolder\WriteLines2.txt”);
//使用foreach循环显示文件内容。
整数计数=0;
char[]splitchar={'|'};
System.Console.WriteLine(“WriteLines2.txt=”的内容);
foreach(行中的字符串行)
{
字符串[]strArr=null;
strArr=line.Split(splitchar);
int iLen=直线长度-1;
对于(count=0;count您的问题(即使在评论中有澄清)并不完全清楚,但这是我目前的猜测:

您有一个文本文件,其中包含多行管道
|
分隔的数据。对于每行数据,您希望捕获前七个值,并丢弃其余值。捕获的数据应发送到数据库进行进一步处理

如果我是正确的,那么您希望修改现有代码,如下所示:

...
string[] strArr;
string[] newArray = new string[7];  

foreach (string line in lines)
{
    strArr = line.Split(splitchar);
    Array.Copy(strArr, newArray, 7);

    // Call DB function, passing newArray
    saveToDB(newArray);
}
...

你的意思是你想保存数据库中的每7行?定义“将数据发送到sql”-这很模糊;这7行的意义是什么?上下文是什么?行(
line
)和列(
strArr
)之间的区别是什么?这都很模糊。但要回答“如果可能”的问题:是的,绝对是;如何取决于上下文“一行文本中有7条管线”是什么意思?根据定义,一行文本不能包含多条其他管线。@Binarus我猜是“管线”这里的意思很简单:
|
@Marc gravel我明白了。谢谢。他指的是管道角色。只是稍微修改了一下,让它工作起来,非常感谢