Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 />

I couldn't find out the problem It inserted upto 126 number files
.Please help me I am in dilemma.
Mahmud
software Engineer
Posted

1 solution

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.
 
Share this answer
 
Comments
Mahmudunnabi 16-Oct-10 2:47am    
I have checked my file because things arise my mind but I didn't get what you said.even now I have checked again all of my lines contain 4th '|' and one thing I should get what line by line but unfortunately I have got wrong order in my database that means mismatch,can u help me a little bit more regarding this.
shakil0304003 16-Oct-10 10:28am    
bool flag = true;

then
catch (Exception)
{
flag = false;
conn.Close();
}

if(flag == false)
messagebox.show("Error");

check this code for finding error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900