return from Hashtable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raghulvarma
    New Member
    • Oct 2007
    • 90

    return from Hashtable

    How should i return a value from hashtable I used a code like
    data access layer
    SqlConnection connection = new SqlConnection(c on);
    SqlCommand cmd = new SqlCommand("sel _data", connection);
    cmd.CommandType = CommandType.Sto redProcedure;
    SqlDataReader dr;
    connection.Open ();
    dr = cmd.ExecuteRead er();
    while (dr.Read())
    {
    Hashtable ht = new Hashtable();
    ht.Add("1", dr.GetValue(0). ToString());
    ht.Add("2", dr.GetValue(1). ToString());
    ht.Add("3", dr.GetValue(2). ToString());
    }
    dr.Close();
    connection.Clos e();
    return ht;
    in business access layer
    return d.getdata1();
    in presentation layer
    Hashtable ht1 = new Hashtable();
    ht1 = b.getdata1();
    for (int j = 0; j <= ht1.Count - 1; j++)
    {
    TextBox1.Text = ht1["1"].ToString();
    TextBox2.Text = ht1["2"].ToString();
    }
    I get the error as Error 'ht' conflicts with the declaration 'Dal.ht'
    what is the mistake i made? how should one return a value in hash table?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Why are you using a HashTable and not a DataTable?
    It's so nice to fill the datatable with a dataadapter with like 2lines of code.
    Then you have access to every value in a nice convient matter.

    Comment

    Working...