[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MM:Dataset capability using pure ASP.net

Posted on 2005-04-11
13
Medium Priority
?
441 Views
Last Modified: 2008-03-10
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
Comment
Question by:stengelj
  • 6
  • 5
  • 2
13 Comments
 
LVL 12

Accepted Solution

by:
laotzi2000 earned 2000 total points
ID: 13756171
put this in your header
      <script language="vb" runat="server">
          public ds as System.Data.DataSet
      </script>
0
 
LVL 9

Author Comment

by:stengelj
ID: 13756213
Then how can I reference it on the page?  

Like this: <%# ds.DataItem("myField") %>?
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13756255
like the following:

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

But you have to populate the dataset first somewhere.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Author Comment

by:stengelj
ID: 13757139
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
 
LVL 37

Expert Comment

by:samtran0331
ID: 13762519
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
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13762600
Yeah, 6 means the seventh row.

If you have only one row returned , you should use 0 instead.
0
 
LVL 9

Author Comment

by:stengelj
ID: 13762704
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
 
LVL 37

Expert Comment

by:samtran0331
ID: 13762778
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
 
LVL 9

Author Comment

by:stengelj
ID: 13762904
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
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13763077
change
<%# ds_myPages.Tables(0).Rows(0).Item("PageID") %>
to
<% =ds_myPages.Tables(0).Rows(0).Item("PageID") %>
0
 
LVL 9

Author Comment

by:stengelj
ID: 13763200
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
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13764081
<% =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
 
LVL 9

Author Comment

by:stengelj
ID: 13765214
Thank you, laotzi2000

I'm rockin' & rollin'.

Someday I'll figure out "=" vs. "#".
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question