TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kevin Rodriguez
NA
10
1.3k
Getting System Out of Range Exception C# Console App
Apr 1 2015 2:52 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Configuration;
using MySql.Data.MySqlClient;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string ID;
string Assay;
string Well;
string Flag;
string SCO;
string Result;
string Value;
int index;
try
{
var files = from file in Directory.EnumerateFiles(@"\\192.168.10.6\\Export", "*.txt", SearchOption.AllDirectories)
from line in File.ReadLines(file)
select new
{
File = file,
Line = line
};
foreach (var f in files)
{
Console.WriteLine("{0}\t{1}", f.File, f.Line);
using (StreamReader sr = new StreamReader(f.File))
{
string readLine;
do
{
readLine = sr.ReadLine();
if (readLine.Length > 1)
{
while (readLine != null)
{
string[] readLineSplit = readLine.Split('|');
ID = readLineSplit[0];
Assay = readLineSplit[1];
Well = readLineSplit[2];
Flag = readLineSplit[3];
Value = readLineSplit[4];
SCO = readLineSplit[5];
Result = readLineSplit[6];
InsertIntoDatabaseMethod(ID, Assay, Well, Flag, Value, SCO, Result);
}
}
} while (!sr.EndOfStream);
}
}
Console.WriteLine("{0} files found.", files.Count().ToString());
}
catch (UnauthorizedAccessException UAEx)
{
Console.WriteLine(UAEx.Message);
}
catch (PathTooLongException PathEx)
{
Console.WriteLine(PathEx.Message);
}
}
private static void InsertIntoDatabaseMethod(string ID, string Assay, string Well, string Flag, string Value, string SCO, string Result)
{
try
{
var connSettings = ConfigurationManager.ConnectionStrings["MyDB"];
string CN = connSettings.ConnectionString;
MySqlConnection conn = new MySqlConnection(CN);
conn.Open();
MySqlCommand cmd = new MySqlCommand("insert INTO testtable (PatientID, Assay, Well, Flag, Value, SCO, Result) VALUES (@id, @assay, @well, @flag, @value, @sco, @result)", conn);
{
cmd.Parameters.AddWithValue("@id", ID);
cmd.Parameters.AddWithValue("@assay", Assay);
cmd.Parameters.AddWithValue("@well", Well);
cmd.Parameters.AddWithValue("@flag", Flag);
cmd.Parameters.AddWithValue("@value", Value);
cmd.Parameters.AddWithValue("@sco", SCO);
cmd.Parameters.AddWithValue("@result", Result);
cmd.ExecuteNonQuery();
}
}
catch (MySqlException re)
{
Console.WriteLine(re);
}
}
}
}
Im getting Index was outside the bounds of the array error with this code.
Reply
Answers (
2
)
restart computer from console application
Event Calender in asp.net c#