I have a dataset that is being filled in one class and I want to access the data from a separate class. How would I do such?
For example, let's take this snippet below that should better explain what I need to accomplish:
namespace Connection { class ServerConnect { public static string FillDataSet() { SqlConnection conn; string sql = null; string data = null; string ConnectionString = "Here is the conection"; conn = new SqlConnection(ConnectionString); conn.Open(); sql = "Here is SQL Statement"; SqlDataAdapter dscmd = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); dscmd.Fill(ds); } } } //Now from this class I want to access the dataset here -- //Will the same method for writing the data work even though it is in a different class? namespace WriteData { class WriteItOut() { for (i = 0; i<= ds.Tables[0].Rows.Count - 1; i++) { for (j = 0; j<= ds.Tables[0].Columns.Count - 1; j++) { data = ds.Tables[0].Rows[i].ItemArray[j].ToString(); //Writing here } } } }