CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Oct 2006
    Posts
    12

    Return array from method

    Is it possible to pass an array from a method?

    An example below:

    Code:
    array GetArray()
    {
    	SqlConnection conn = new SqlConnection("Server=127.0.0.1;User ID=me;Pwd=dude;database=mine;);
    	SqlDataReader rdr = null;
    	conn.Open();
    	SqlCommand cmd = new SqlCommand("select * from Table", conn);
    	rdr = cmd.ExecuteReader();
    	string[,] names = new string[cnt,6]; //creates a two dimensional array
    	rdr.Read(); //initial read
    	for (int i=1; i < cnt; i++)
    	{
    		for (int j=1; j < 6; j++)
    		{
    			names[i,j] = rdr[j].ToString();
    		}
    		rdr.Read();
    	}
    	conn.Close();
    	return names
    }
    Last edited by Westerberg; October 25th, 2006 at 09:25 AM. Reason: changed title

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured