Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Into below code i am trying to show the currency into lable called: "CountCurrencLbl" depending country which is cookie value from table Currency i have did the first part of the code but i did not know how to complete it so please could you help me to complete the code and show currency depending on country.

C#
HttpCookie cookie = Request.Cookies.Get("Location");
                if (cookie["Location"] == null)
                {
                    DataTable StateDT = new DataTable();
                    using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["BeravaConnectionString"].ConnectionString))
                    {
                        // Create the SelectCommand.
                        SqlCommand command = new SqlCommand("SELECT Currency FROM Currency WHERE Country = @Location", con2);
                        var Location = cookie.Value;
                        command.Parameters.AddWithValue("@Location", Location);

                        
                }
Posted
Comments
Krunal Rohit 8-Nov-15 7:22am    
You mean:
command.Parameters.AddWithValue("@Location", cookie["Location"]); ??

-KR
Member 10690878 8-Nov-15 13:30pm    
Hi no i need some one to help me by complete the rest of the code

1 solution

Use ExecuteScalar

https://msdn.microsoft.com/en-gb/library/system.data.sqlclient.sqlcommand.executescalar(v=vs.110).aspx[^]

C#
command.Parameters.AddWithValue("@Location", Location);
string c = (string) command.ExecuteScalar();


If it "doesn't work" check the "Location" variable has what you expect, or try surrounding the names in your SQL with square brackets as Currency is probably a reserved word

SqlCommand command = new SqlCommand("SELECT [Currency] FROM [Currency] WHERE Country = @Location", con2);
 
Share this answer
 
Comments
Member 10690878 8-Nov-15 19:40pm    
Hi @F-ES Sitecore
Thanks for your reply and explanation, but i need to help me with full code as the rest i dont know how to complete it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900