Question : get data from class

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
/// Summary description for Currancyrate
/// </summary>
public class Currancyrate
{
   
    string connStr = ConfigurationManager.ConnectionStrings["shivcn"].ConnectionString;

    public String[] GetCurrancyrate(string exchangerate)
    {
        string rate="0";
        string symble="0";

        SqlConnection connection = new SqlConnection(this.connStr);
        connection.Open();
        SqlCommand command = new SqlCommand("select * from shiv.exchange_rate where country ='" + exchangerate + "'", connection);
        SqlDataReader reader = command.ExecuteReader();
        if (reader.Read())
        {
            rate = reader["rate"].ToString();
            symble = reader["symbol"].ToString();
        }
        connection.Close();
        connection.Dispose();
        reader.Close();
        reader.Dispose();
        command.Dispose();

        return new String[] { rate, symble };
    }
}




and I call This class
 this.lblcurrency.Text = d.GetCurrancyrate(this.Session["exchangerate"].ToString())[0].ToString() ;
             this.Lblcusymb1.Text = d.GetCurrancyrate(this.Session["exchangerate"].ToString())[1].ToString();



But It Fire Two Time


How I call This Class

Answer : get data from class

Of course it will fire 2 times. Because you are asking it to.

You need to put the result in a separate variable like this:

string[] currencies = d.GetCurrancyrate(this.Session["exchangerate"].ToString());

Then follow this by using:

this.lblcurrency.Text = currencies[0].ToString();
this.Lblcusymb1.Text = currencies[1].ToString();
Random Solutions  
 
programming4us programming4us