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!!!!!
10 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 4, 2014, 6:54 PM
So I'm totally mystified as to why it's still not working :-/
You might try inserting the MessageBox line in your own code to see what you get.
Sousa PamboPosted Mar 9, 2014, 3:28 PM
Sousa PamboPosted Mar 4, 2014, 10:47 AM
Is there some more ideia, i'm empty now....
VulpesPosted Mar 3, 2014, 4:39 PM
Sousa PamboPosted Mar 3, 2014, 2:47 PM
I have one declaration .... here is the code
---------------------------------------------------------------------------------------
Please check where I'm doing wrong!!!!!!
VulpesPosted Mar 3, 2014, 9:23 AM
I notice that in frmLogin_Load you call the configTxt method like this:
CG.configTxt(@"c:\program Files\a.txt");
which suggests that it's in a different class to the form itself.
If so, is the declaration of the lineAccess ArrayList and the conectaSql method in the same class as configTxt or are they in the form itself?
What I'm wondering here is whether you might have inadvertently declared two ArrayLists one in the form and one in the class and that one of these is getting populated but the other one is still empty.
Sousa PamboPosted Mar 3, 2014, 8:41 AM
- I made some tests to see if it reads the file or not and I found it does (I changed the "a.txt" to "b.txt" the msg was "b" doesn't exist, this bug doesn't show for "a" file name).
- In the file ("a.txt") I only have "." because for while I testing my application with the local server, it means I have only one line to be read in the file.
So I don't understand the error.
Please help me on this!!!!!!!!!
VulpesPosted Mar 2, 2014, 3:45 PM
If an index of 0 can't be found, then that would suggest that either there are no lines in the file or the file can't be found at all.
Sousa PamboPosted Mar 2, 2014, 2:57 PM
Error is ..... {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}
Biswa Pujarini MohapatraPosted Mar 1, 2014, 9:51 PM