Array values from hashtable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gorden blom

    #1

    Array values from hashtable?

    Hello,

    I'm working on a ASP.NET/C# school project and I'm having some
    difficulties. I'm trying to extract the values of an array, and print
    them to my screen. I've added the array to a hashtable. I know how to
    extract something like a string, so that isn't the problem. Can
    someone help me?

    Sourcecode:

    using System;
    using System.Collecti ons;
    using System.Configur ation;
    using System.Data;
    using System.Data.Sql Client;
    using System.IO;
    using System.Text;
    using System.Web;
    using System.Web.Secu rity;
    using System.Web.UI;
    using System.Web.UI.W ebControls;
    using System.Web.UI.H tmlControls;
    using System.Text.Reg ularExpressions ;

    namespace Gorden.Multiple {

    public class MyCodeBehind : Page {

    public string strInput;
    public string strOutput;

    public void Page_Load(objec t sender, System.EventArg s e) {

    if(!IsPostBack) {

    DataSet myDataSet = new DataSet();

    SqlConnection myConnection = new
    SqlConnection(C onfigurationSet tings.AppSettin gs.Get("connect ionstring"));

    SqlDataAdapter myData = new SqlDataAdapter( "SELECT [ID],
    [Naam] FROM [Categorie]", myConnection);

    myConnection.Op en();

    myData.Fill(myD ataSet, "Input");

    int intRows = myDataSet.Table s["Input"].Rows.Count;
    int intColumns = myDataSet.Table s["Input"].Columns.Count;


    Hashtable myTable = new Hashtable();

    string [,] myArray = new string [intColumns,intC olumns];

    int i = 0;
    int j = 0;

    foreach (DataRow myRow in myDataSet.Table s["Input"].Rows)
    {
    string strIdentifier = myRow[0].ToString();
    foreach (DataColumn myCol in
    myDataSet.Table s["Input"].Columns){
    string strValue = myRow[myCol].ToString();
    string strKey = myCol.ToString( );

    if(i <= intColumns - 1) {
    myArray [i,j] = strKey;
    j++;
    myArray [i,j] = strValue;
    i++;
    j = 0;
    }

    if(i == intColumns) {
    myTable.Add(str Identifier, myArray);
    System.Array.Cl ear(myArray, 0, intColumns -
    1);
    i=0;
    j=0;
    }
    }
    }
    vullen(myTable) ;

    }
    }

    public void inlezen() {

    strInput = null;
    StreamReader srRead = File.OpenText(" D:\\product\\me nu.tpl");
    srRead.BaseStre am.Seek(0, SeekOrigin.Begi n);
    strInput = srRead.ReadToEn d();
    srRead.Close();
    }

    public void vullen(Hashtabl e aTable) {

    Do something to get values of the array......
    }

    protected override void Render(HtmlText Writer writer) {

    writer.Write(st rOutput);
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArg s e) {
    InitializeCompo nent();
    base.OnInit(e);
    }

    private void InitializeCompo nent() {
    this.Load += new System.EventHan dler(this.Page_ Load);
    }
    #endregion
    }
    }
Working...