Friday, March 16, 2012

Passing a Variable

Ok here I go again, I am for the most part a novice with ASP.NET. I have an FAQ Knowledge base system that I am currently developing. The basics of it are as follows:

Data is stored on SQL DB, Tables have not been created but the tables will be set up accordingly when I reach that stage. THey will contain the information to display to the user querying the system for answers.

Now to the meat of it, and I may be thinking to hard on the steps to make it work but this is what I have come up with to impliment. Basic page that has a menu driven system I guess similiar to MSDN menu system.

//menu
////category1
////////topic1
////////topic2
////////topic3
////////topic4
////category2
////////topic1
////////topic2
////////topic3
////////topic4

Each menu item will target an iframe to the right of it, again similair to MSDN. here is where my dilema comes into play.

I could just create a static page for each menu item and have it target the iframe, but that would defeat the dynamic function of it, not to mention way to much data to enter when I could just enter it once into the DB for uses beyond the FAQ Knowledge base system.

So I was thinking I have asp.net page that is the source for the iframe i.e. [iframe name="faq" src="http://pics.10026.com/?src=faq.aspx"][/iframe]

This faq.aspx would be such that it would maintain the DB connection string and dataset and so forth for actually displaying the data queryed from the DB and each menu item somehow pass a value that when clicked would load the faq.aspx with the value it is and perform a select statment on the DB based upon the value that it was predifined with.

i.e.

//menu
////category1
////////topic1 = 1_1

sending the value 1_1 to the page_load() event where a select statement would query database with value that is 1_1
where 1_1 = topic_id 1234

I guess here is a my idea of what the code could look like

Sub Page_Load()

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

Dim SelectCommand As String = "select * from DB where topic_id = @dotnet.itags.org.topic_id"

MyConnection = New SqlConnection()
MyConnection.ConnectionString="my connection string"
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@dotnet.itags.org.topic_id", SqlDbType.Int, 4))
MyCommand.SelectCommand.Parameters("@dotnet.itags.org.topic_id").Value = passedvariable??

DS = new DataSet()
MyCommand.Fill(ds, "DB")

MyDataGrid.DataSource=ds.Tables("DB").DefaultView
MyDataGrid.DataBind()

End Sub

Or something like that. I hope I am getting my point across, my question is how to get that passed variable over to that select statment. I know how to do the select statement just not getting the variable to it. Any suggestions would be a great help.You'll want to pass a parameter in the URL. For example faq.aspx?id=1234

Then you can read it in your code by access the Request.QueryString collection:

MyCommand.SelectCommand.Parameters("@.topic_id").Value = Request.QueryString("id")

0 comments:

Post a Comment