hello,
this is the error i get at line
string ins = "insert into assign values('" + arrText[0] + "','" + arrText[1]+"')"; //insert command
Index was out of range. Must be non-negative and less than the size of the collection
Any suggetions??? my code is here:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Data.OleDb;
using System.Data.OracleClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
StreamReader objReader = new StreamReader("c:\\test.txt");
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
foreach (string sOutput in arrText)
richTextBox1.Text = sOutput;
}
private void button2_Click(object sender, EventArgs e)
{
StreamReader objReader = new StreamReader("c:\\test.txt");
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
OracleConnection oracleConect = null;
string connectStr = "Data Source=xe;Persist Security Info=True;User ID=system;Password=kuetcse;Unicode=True";
oracleConect = new OracleConnection(connectStr);
oracleConect.Open();
OracleCommand command = oracleConect.CreateCommand();
command.Connection = oracleConect;
string ins = "insert into assign values('" + arrText[0] + "','" + arrText[1]+"')"; //insert command
command.CommandText = ins;
command.ExecuteNonQuery();
oracleConect.Close();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Loading
Jon BellamyPosted Jul 4, 2009, 4:44 AM
I've eited my previous post as I realised you created arrText at both levels. I think the problem may be where you do while(sline != null) so try the following (you'll need to add bits in):
using (StreamReader reader = new StreamReader("c:\\test.txt"))
{
String sline = null;
while (reader.EndOfStream != true)
{
arrText.Add(sline);
}
}
You'll notice that the using statement will auto-close the resource on the StreamReader saving you the hassle! You can also use a using statement with the OracleConnection if you wish.
Hope that helps - Jon