• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

MM:Dataset capability using pure ASP.net

I have been using Dreamweaver's <mm:dataset/> connections in most of my site but I want to expand my horizons and be able to do what I want without relying on Dreamweaver so much.

For the most part, I get how to do all the usual stuff (Insert/Update/Delete) and how to bind things like repeaters and datagrids.  However, what I can't figure out is how to make my dataset (datareader, datatable, whatever...) available to the page without binding it to a control inside a form? Do I need to dim a public datatable and fill it or what?

In DW I create a <mm:dataset id="myDS"/> and reference that dataset anywhere on the page by using:
<%# myDS.DataField("myField", Container) %>

How do I get that flexibility without using Dreamweaver's control?  Please show examples in VB. You can show me C++ but I may or may not be able to follow it.
0
stengelj
Asked:
stengelj
  • 6
  • 5
  • 2
1 Solution
 
laotzi2000Commented:
put this in your header
      <script language="vb" runat="server">
          public ds as System.Data.DataSet
      </script>
0
 
stengeljAuthor Commented:
Then how can I reference it on the page?  

Like this: <%# ds.DataItem("myField") %>?
0
 
laotzi2000Commented:
like the following:

<%# ds.Tables(0).Rows(6).Item("col1") %>

But you have to populate the dataset first somewhere.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
stengeljAuthor Commented:
Ok, I've been tinkering with this an I think I'm getting it figured out.  However, I can get my data do display on the page.  The database connection seemed to work ok and it think everything is getting populated in my dataset but I get nothing after "Test:" and no error is being generated.  Am I trying to do something weird here? What is the preferred way to do a details page (where I'm only displaying information for a single record)?  Thanks for your help.

Here's my code:

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1"  Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDB" %>
<html>
<head>
<script runat="server">
      public ds_myMovies as New DataSet
      sub Page_Load(sender as Object, e as EventArgs)
            Try
                  Dim MyConnection As OleDbConnection
                  Dim MyCommand As OleDbDataAdapter
                  dim MyDataset As DataSet
                  dim sqlstr As String
                  sqlstr = "SELECT * FROM tbl_Films WHERE FilmID=2;"
                  MyConnection = New OleDbConnection _
                        ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=C:\Data\Movies\Databases\Movies.mdb")
                  MyCommand = New OleDbDataAdapter(sqlstr, MyConnection)
                  MyCommand.Fill(ds_myMovies)
            Catch ex as Exception
                  lbl_dbError.Text = ex.ToString
            End Try
      End Sub
</script>
</head>
<body>
      Test: <%# ds_myMovies.Tables(0).Rows(6).Item("FilmTitle") %>
      <asp:label ID="lbl_dbError" runat="server" />
</body>
</html>
0
 
samtran0331Commented:
Based on the query, it looks like it returns only one row? I'm assuming filmID=2 means one movie gets returned, in which case, the
".Rows(6)" doesn't exist, your error label should tell you tho which kinda stumps me.
Try changing ".Rows(6)" to "(0)"
or
Try removing your the "Where" part of your sql so the ds returns all rows and see if rows(6) works.

Now, do you feel like listening to a rant?(I'll keep it short)
I used Dreamweaver since v3 and love it to death...until .Net came out.
DMX did a great job of making their .Net stuff similar to classic asp...but in reality, .Net is not like classic ASP and using DMX to do .Net, you lose a lot of functionality and power of .Net.
I spent a lot of time figuring out how to do .Net "the DMX way"...so in addition to learning how to do things the pure .Net way, then I had to figure out how to make it work in DMX. Working around the DMX dataset is tough.  
When I switched to Visual Studio.Net, I felt like I was cheating on my girlfriend...it was hard to let go of DMX, but was worth it.
If you're going to stay in DMX for .Net, check out CommunityMX especially articles by Heidi Bautista...most the really good tutorials on the site are hers...I think she is part of the admin too...but she's the DMX.Net guru.
But if you're going to be a true web "application" developer in .NET, I would strongly strongly suggest switching to Visual Studio.Net.

0
 
laotzi2000Commented:
Yeah, 6 means the seventh row.

If you have only one row returned , you should use 0 instead.
0
 
stengeljAuthor Commented:
I've tried all that you suggested.  I didn't mean to post it with the "6" in there.  I've tried it with returning all records in the table and with different row number.  I am on a different computer today so I am going to try it with a different database and setup and see what happens.  I will also make sure that my dataset is getting filled-that could be why nothing gets returned.  I let you know how it turns out.

Your 'rant' is actually helpful.  I am trying to get away from relying on DW for my applications and this is really the only thing left that I haven't figured out how to do in VS.NET.  I'll probably still use DW for my design and layout--I really like the way the CSS stuff is so easy to use.
0
 
samtran0331Commented:
One other thing to try once you verified the conn and the ds is instead of outputting in the html between <%#... %>
is to put a label in the html and then set the label.text at the end of your sub right before the "catch"

or instead of
ds_myMovies.Tables(0).Rows(6).Item("FilmTitle")

try this format:
ds_myMovies.Tables(0).Rows(6)("FilmTitle")
0
 
stengeljAuthor Commented:
Ok, did some more testing and the dataset is getting filled because I can response.write in the function and get a value and I can send that value to a label just fine but I can get a value from the page body.  It's like the dataset gets emptied at the end of the function.

This...

<script runat="server">
     public ds_myPages as New DataSet
     sub Page_Load(sender as Object, e as EventArgs)
          Try
               Dim MyConnection As OleDbConnection
               Dim MyCommand As OleDbDataAdapter
               dim MyDataset As DataSet
               dim sqlstr As String
               sqlstr = "SELECT * FROM tbl_Pages WHERE PageID=1;"
               MyConnection = New OleDbConnection _
                    ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                    "Data Source=C:\Data\Web\MultipleInserts\WebContent.mdb")
               MyCommand = New OleDbDataAdapter(sqlstr, MyConnection)
               MyCommand.Fill(ds_myPages)
               Response.Write("Response.Write Test: " & ds_myPages.Tables(0).Rows(0).Item("PageID") & "<br>")
               lbl_Test.Text = "Label Test: " &  ds_myPages.Tables(0).Rows(0).Item("PageID")
          Catch ex as Exception
               lbl_dbError.Text = ex.ToString
          End Try
     End Sub
</script>
</head>
<body>
     HTML Test: <%# ds_myPages.Tables(0).Rows(0).Item("PageID") %><Br>
     <asp:Label ID="lbl_Test" runat="server" />
     <asp:label ID="lbl_dbError" runat="server" />
</body>
</html>

Returns....

Response.Write Test: 1
HTML Test:
Label Test: 1
0
 
laotzi2000Commented:
change
<%# ds_myPages.Tables(0).Rows(0).Item("PageID") %>
to
<% =ds_myPages.Tables(0).Rows(0).Item("PageID") %>
0
 
stengeljAuthor Commented:
Bingo! That did it.  I should have tried that sooner.

I don't really understand the difference between "#" and "=".  
If it's not a long conversation, could you enlighten me? Or, point me in a direction to figure it out?
0
 
laotzi2000Commented:
<% =something %> is simple,
it just compute the value of something on server side and put it here.

<%# somtething %> is related to data binding,
not sure of its usage yet.
0
 
stengeljAuthor Commented:
Thank you, laotzi2000

I'm rockin' & rollin'.

Someday I'll figure out "=" vs. "#".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now