Dynamic Dataset's for a form

esilva002

Member
Joined
Jun 16, 2010
Messages
6
Programming Experience
1-3
Hi,
I have a application that I would like to load a dynamic dataset based off of a array. My array is multidimensional and sets many values for my form.
example:
pWebSiteInfo(0, 1) = Home (Name of the Form)
pWebSiteInfo(1, 1) = index.aspx (File name of the web page it correlates to)
pWebSiteInfo(2, 1) = tblWebPage01 (Name of the table I want data to load my form)

Now, I have a Loop that sets a varaible (tbl) to the correct table, in this case it is tblWebPage02.

VB.NET:
'Sets tbl to the name of the table
        Do Until pWEBSiteInfo(0, Ctr0) = Text
            Ctr0 = Ctr0 + 1
            tbl = pWEBSiteInfo(2, Ctr0)
        Loop

Then, I want to fill my dataset with variable tbl

VB.NET:
cDataSetTA.Connection.ConnectionString = pWEB_Server & pWEB_IntCatalog & pWEB_UserID & pWEB_Password
            cDataSetTA.Fill(cDataSet.tbl)

The problem is that I don't know what type my variable 'tbl' should be. Right now im using string, which i know is wrong. Any thoughts? Thanks in ahead of time.
 
You seem to be trying to generate a somewhat horrendous mix of ultra-generic and type-specific code.. Youre using a tableadapter which is a type specific device but specifying everything else about the page in an array (you could at least use a proper class, with a .Title, .Url, .TableName etc property to make the code readable, instead of filling it with magic numbers.. pageInfoArray(3) ' 3 means the name of the blah blah control)

Maintenance nightmare and as a professional coder, if I came across code like that, i'd delete and rewrite it rather than try and maintain it.. I think you too will regret it further down the line.. When you hit a problem of this fundamental nature (trying to parameterise the types of objects youre referring to, without being able to build a generic hierarchy so you can refer to them using polymorphic features of an OO language becuse the framework is already fixed by someone else) it usually means youre attacking the problem in a way that's very wrong with respect to the design

If you wish to persist though, why not store the name of the table in a string, and use a dataadapter instead, the Fill(DataSet, String) overload.. Keep it all generic rather than dipping into type specific stuff like tableadapters. Youll have to parameterise everything about the dataadapter though, including the query, the parameter list..
 
OK Well here is the scope and see if this makes sense. I have a asp.net website that pulls all of the text from a sql database, and that works great. I also want to create a application that will open the site (or any other site), and be able to edit that site through the application. I am going to make every table of my sites generic tables like tblWebPage01 = index.aspx instead of tblIndex = index.aspx.

Now, you said that I could use a data adapter instead. I really have little experience with this and am only coping from a project I did in college. What would the code of that be? Sorry if i have given too much info but a little pork never hurt anyone.
 
Ok Here is what I got now. I have to bind it to my text boxes next right? and how would I do that?

VB.NET:
'Sets tbl to the name of the table
        Do Until pWEBSiteInfo(0, Ctr0) = Text
            Ctr0 = Ctr0 + 1
            Table = pWEBSiteInfo(2, Ctr0)
            If Ctr0 = 50 Then
                MsgBox("Connection Error", MsgBoxStyle.Critical, "Rockware Web Interface - Error")
                Exit Sub
            End If
        Loop

        ' Assumes that connection is a valid SqlConnection object.
        Dim queryString As String = "SELECT * FROM " & Table
        Dim adapter As SqlDataAdapter = New SqlDataAdapter(queryString, pWEB_Server & pWEB_IntCatalog & pWEB_UserID & pWEB_Password)

        Dim WebDataSet As DataSet = New DataSet
        adapter.Fill(WebDataSet, "Name")
 
Ok, Now i have bound the text boxes to the dataset through this:

VB.NET:
Try

            'Some Comment!!!
            Dim QueryString As String = "SELECT * FROM " & Table '& " WHERE wp01Notes = Contact Header"
            Dim Adapter As SqlDataAdapter = New SqlDataAdapter(QueryString, pWEB_Server & pWEB_IntCatalog & pWEB_UserID & pWEB_Password)

            Dim WebDataSet As DataSet = New DataSet
            Adapter.Fill(WebDataSet, Table)

            cBindingSource.DataSource = WebDataSet
            cBindingSource.DataMember = Table

            Me.txtHeader1.DataBindings.Add("Text", cBindingSource, "wp01Text") 'currently pulls in 'this is the detail header' for all
            Me.txtParagraph1.DataBindings.Add("Text", cBindingSource, "wp01Text")
            Me.txtHeader2.DataBindings.Add("Text", cBindingSource, "wp01Text")
            Me.txtParagraph2.DataBindings.Add("Text", cBindingSource, "wp01Text")
            Me.txtHeader3.DataBindings.Add("Text", cBindingSource, "wp01Text")
            Me.txtParagraph3.DataBindings.Add("Text", cBindingSource, "wp01Text")
            Me.txtFooter.DataBindings.Add("Text", cBindingSource, "wp01Text")

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Rockware Web Interface - Error")
        End Try

The only thing is that I am getting the first record on all of my text boxes. How would I get the footer to show info for the footer. i thought I could make multiple datasets with a where clause like i have but i commented it out for now.
 
Youre not really asking ADO.NET questions; ADO.NET is a technology that connects to a databse, but youre asking ASP.NET questions and they would be better off posed in the ASP areas of the forums. I don't do ASP, but one thing I can tell you: dont put MsgBoxes in ASP code!
 
Back
Top