Sousa Pambo

Sousa Pambo

  • NA
  • 92
  • 23k

Read txt array on c#

Mar 1 2014 3:29 PM
Hi fellows, I need your help on this I have a ..... "Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}..... Error
 
public ArrayList lineAccess=new ArrayList();
 
public void configTxt(string ficheiro)
{
StreamReader conjLines;
string lines;
try
{
conjLines = new StreamReader(ficheiro);
lines = conjLines.ReadLine();
while (lines != null)
{
lineAccess.Add(lines);
lines = conjLines.ReadLine();
}
conjLines.Close();
}
catch (Exception erro)
{
throw erro;
}
}
 
-----------------------------------------------------------------------------------------------
this is my connection method, and I get the server name at some txt file
 
public string conectaSql(int i)
{
//string connectionString = Properties.Settings.Default.ConnectionString;
string dv = "";
try
{
string mysql = "select configura from conStringTbl where id= '" + i + "'";
using (SqlConnection myconn = new SqlConnection("Persist Security Info=False;Server=" + lineAccess[0] +"; DataBase=dbconString; user=ka; password =newbegining"))
{
myconn.Open();
using (SqlCommand comand = new SqlCommand(mysql, myconn))
{
SqlDataReader dtreader = comand.ExecuteReader();
if (dtreader.Read())
{
dv = dtreader[0].ToString();
}
return dv;
}
}
}
catch (Exception erro)
{
throw erro;
}
}
______________________________________________
on form login load I get the parameter 
 
private void frmLogin_Load(object sender, EventArgs e)
{
CG.configTxt(@"c:\program Files\a.txt"); 
}
 
Thanks!!!!! 
 

Answers (10)