Click to See Complete Forum and Search --> : Help with Method (pass / return) and database


Westerberg
October 25th, 2006, 02:11 PM
I need the following methods to work and I think they will but I'm not sure what to pass in regards to the ????? that are in each. Any help is most appreciated.


void SqlConnect()
{
SqlConnection conn = new SqlConnection("Server=127.0.0.1;User ID=me;Pwd=dude;database=mine;);
SqlDataReader rdr = null;
conn.Open();
return ???????;
}

void SqlDisConnect(???????)
{
conn.Close();
}



string[,] FillArray(???????)
{
SqlCommand cmd = new SqlCommand("select * from Table", conn);
rdr = cmd.ExecuteReader();
rdr.Read();
string[,] names = new string[100,6];
for (int i=1; i < 100; i++)
{
for (int j=1; j < 6; j++)
{
names[i,j] = rdr[j].ToString();
}
rdr.Read();
}
conn.Close();
return names;
}

creatorul
October 25th, 2006, 03:09 PM
private SqlConnection conn;
private SqlDataReader rdr ;
privaet SqlCommand cmd ;
void SqlConnect()
{
conn = new SqlConnection("Server=127.0.0.1;User ID=me;Pwd=dude;database=mine;");
SqlDataReader rdr = null;
conn.Open();

}

void SqlDisConnect()
{
conn.Close();
}

//I forgot to erase the question marks from the following line, but they are gone now :)
string[,] FillArray()
{
cmd = new SqlCommand("select * from Table", conn);
rdr = cmd.ExecuteReader();
rdr.Read();
string[,] names = new string[100,6];
for (int i=1; i < 100; i++)
{
for (int j=1; j < 6; j++)
{
names[i,j] = rdr[j].ToString();
}
rdr.Read();
}
SqlDisConnect();
return names;
}


In this code I replaced the question marks with something suitable. I don't know if your code works for your database but this is the way I think you should do the coding.