Hi dear,
I am making a small program in ASP.NET in C# but am not able to set the label names from a Database table.
Table Name: Columns
col_id col_name
======= =============== ===========
Label1 City ID
Label2 City Name
Label3 City Addrs
i want to set all the lables from the table "Columns".
This function will be called at the time of Page Load()
More Details of My code "I am not Sure It is True"
In Class file Main.cs
This Function is calling on Page_Load of Default.aspx
Expecting Your Help
I am making a small program in ASP.NET in C# but am not able to set the label names from a Database table.
Table Name: Columns
col_id col_name
======= =============== ===========
Label1 City ID
Label2 City Name
Label3 City Addrs
i want to set all the lables from the table "Columns".
This function will be called at the time of Page Load()
More Details of My code "I am not Sure It is True"
In Class file Main.cs
Code:
public static string GetColum_Des(string p_opt_id)
{
string str = System.Configuration.ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
SqlCommand cmd;
SqlDataReader rd;
SqlConnection con = new SqlConnection(str);
unsafe
{
string str1, str2;
con.Open();
cmd = new SqlCommand("select col_id,col_name from LOCATIN_DETAIL where opt_ID=@p_opt_id ", con);
cmd.Parameters.AddWithValue("@p_opt_id", p_opt_id);
rd = cmd.ExecuteReader();
while (rd.Read())
{
str1 = rd["col_id"].ToString() + "Text";//I want to get Label Id from here +.Text Means "Label1.Text" in str
str2=rd["col_name"].ToString();//I want to get Label value from here which had stored in database fied col_name
str1 = str2; //Means Label1.Text=str2 is it possible
}
}
return "";
}
Code:
protected void Page_Load(object sender, EventArgs e)
{
Main.GetColum_Des("001001001")//Passing value of p_opt_id
}
Comment