文件中的问题(无法获取所有行) [英] Problems in files(not getting all lines)
本文介绍了文件中的问题(无法获取所有行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
我已经开发了一个从目录中读取文件的应用程序.
现在的问题是我可以获取正确的行数或文件长度,但没有在数据库中插入所有行.
Dear,
I have developed a application that read file from directory.
Now the problem is I can get the correct line count or length of a file but I wasn''t insert all lines in my database.
<br />
public void InsertFNF(FileInfo file)<br />
{<br />
string strConString = ConfigurationSettings.AppSettings["dbConnectionString"];<br />
<br />
string textLine = "";<br />
System.IO.StreamReader obsReader;<br />
int CountLine = File.ReadAllLines(file.FullName).Length;<br />
//I am getting 4486 lines in my file<br />
<br />
obsReader = new System.IO.StreamReader(file.FullName);<br />
do<br />
{<br />
textLine = obsReader.ReadLine();<br />
string[] allFile = textLine.Split(''|'');<br />
string strSql = "";<br />
string query;<br />
<br />
OleDbConnection conn = new OleDbConnection(strConString);<br />
conn.Open(); // 1. Instantiate a new command with command text only<br />
<br />
// foreach (DataRow prow in oDSfull.Tables["CM_SYSTEM_MENU"].Rows)<br />
// {<br />
try<br />
{<br />
query = @"INSERT INTO SERVICE_CDR_FO_PARTY(CDR_TYPE,A_PARTY,TIME_STAMP,SERVICE_EVENT,CDR_FILE) "<br />
+ "VALUES (''" + allFile[0].ToString() + "'', ''" + allFile[3].ToString() + "'',TO_DATE(" + allFile[2].ToString() + ",''yyyyMMDDHH24MISS''),''" + allFile[1].ToString() + "'',''" + file.Name.ToString() + "'')";<br />
<br />
OleDbCommand olcmd = new OleDbCommand(query); // 2. Set the Connection property<br />
olcmd.Connection = conn;<br />
olcmd.ExecuteNonQuery();// 3. Call ExecuteNonQuery to send command<br />
<br />
}<br />
catch (Exception)<br />
{<br />
<br />
conn.Close();<br />
}<br />
}<br />
//while (CountLine!=1);<br />
while (obsReader.Peek() != -1);<br />
obsReader.Close();<br />
<br />
<br />
<br />
}<br />
<br />
我找不到问题,它最多可以插入126个数字文件.
请帮助我,我陷入了困境.
马哈茂德
软件工程师
I couldn''t find out the problem It inserted upto 126 number files
.Please help me I am in dilemma.
Mahmud
software Engineer
推荐答案
我认为这是由于您的try catch发生的,如果您未使用try catch,则您的程序将崩溃.因为您编写了llFile [3] .ToString(),但我觉得分割"|"后文件中的某些行没有4个元素.所以,我认为在您的程序中会发生异常.进行可变计数以计算发生异常的行数.如果您这样做,我认为您将能够找到您的问题.
I think this occur for your try catch, if you did not use try catch, then you program will be crash. Because you wrote llFile[3].ToString() but i thing some of your lines in the file has not 4 elements after spliting ''|''. So, i think in your program exception occur. take a variable count for count the number of lines that the exception occur. If you do this, i think you will able to find your problem.
这篇关于文件中的问题(无法获取所有行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文