I have a table in my sql database, that comtains data.
In this table, I have the id (int), and two two column names (each nvarchar(50) ).
Now. Say. Using C# in codebehind, I want to place one of the “nvarchar” in a string.
I wish to use the id from my browsers url, to choose the data with.
Lets say, my url is “http://localhost:49530/Forum/Thread.aspx?id=4”
In my table, I have ThreadID, Topic and Message.
So it needs to write the data from “Topic”, that has ThreadID=4, into a predefined variable.
I wish to do it in page_load in code behind. And finally show that data in a label on the aspx page.
I am totally blank. (as well as what to google for. Have googled the whole day on this).
I have cooked some code now, using the example given to me. Something is wrong.
SqlConnection conn_Kategori = new SqlConnection(WebConfigurationManager.ConnectionStrings["Computer_Klubben_CommunitySiteConnectionString"].ConnectionString);
int TraadVaelger = int.Parse(Request.QueryString["id"]);
string OutputToLabel;
using (conn_Kategori)
{
conn_Kategori.Open();
SqlCommand OverfoerTraadNavnet = new SqlCommand("SELECT KatNavn FROM KategoriTabel WERE Katnavn = @KatNavn", conn_Kategori);
OverfoerTraadNavnet.CommandType = CommandType.Text;
OverfoerTraadNavnet.Parameters.AddWithValue("@KatNavn", TraadVaelger);
OverfoerTraadNavnet.ExecuteReader();
OutputToLabel = OverfoerTraadNavnet.ExecuteReader().ToString();
Stien.Text = OutputToLabel;
conn_Kategori.Close();
}
1 Answer