Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 855
  • Last Modified:

Sample asp.net database driven website

I don't have any problems writing classic asp applications but making the switch to asp.net has been a daunting task. I have read a few books that seem to have been a waist of time and now I am looking to do exactly what I did for classic asp for asp.net. I looked over a small sample classic asp database driven website and found out how thing were done i.e. insert, update, delete records from a data base. I was hoping to be able to find something like that for asp.net written in vb.net. Unfortunately everything that i have found has been just slightly short of what I am looking for.

Does any one know some place that I could download a simple asp.net driven website to learn from the source code?
0
nuweb
Asked:
nuweb
1 Solution
 
NetworkArchitekCommented:
Well, there are a lot of links I could give you. Honestly, the most helpful thing I have ever found for quickly learning stuff like this is:

http://www.learnvisualstudio.net

Its very cheap and he goes into all the details you will need to get started. The main videos you will want to look at are the VB.NET videos dealing with ADO.NET and then he also has a seperate series on ADO.NET. It is well worth the price in my opinion.
0
 
NetworkArchitekCommented:
If this isn't enough then if you post a couple specific thingsyou need help with then we can help more. I'll give you a brief example, I've got some down time.

Ok, suppose you have an Access database with a table called "Orders" and this table has columns like "ID," "CUSTNAME, " "PRODUCTID," "QTY." Suppose this is called Sales.mdb.  So some generic stuff you would do to access this in a form would be like:

1: Create your connection object with a connection string
2: Create your "command" object
3: Well, now you have the choice of just using the command object OR using a "Dataset" and DataAdapter

In this example, let's create a DataGrid called dg. We'll just put all the data from the table into the DataGrid. If this is access you need to do a "imports System.Data.OleDB"


------------------------------------------------------------
    private connectString As String = " ..."    ' Type in your connection string here
    private oConn As New OleDBConnection(connectString)
    private oCmd As OleDBCommand

    ....
   private sub fillDataGrid()
             oCmd = New OleDBCommand()
             oCmd.Connection = oConn
             oCmd.CommandText = "SELECT * FROM ORDERS"
 
             Dim dsOrders as New Dataset
             Dim oAdapter As New OleDBDataAdapter(oCmd)

            oAdapter.Fill(dsOrders)
            dg.DataSource = dsOrders.Tables(0)  ' So fill dg with a DataTable from the DataSet, otherwise you will have a "drilldown"
            oAdapter.Dispose()
   End Sub

--------------------------------------------

Well, that includes the basics. I don't think I made any mistakes, but if I did I'm sure someone will point them out. =) Hope this is somewhat useful.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Arthur_WoodCommented:
I would suggest that you might talk a look at

Expert One-On-One
Visual Basic.NET Business Objects
Rockford Lhotka
APress
ISBN: 1590591453

He discusses how to build a VB.NET application from the ground up, and then shows how to use the Business objectys to drieve a web-site, connected to a SQL Server database backend.

All of the Data Access is carried out in objects that are independent of the UI (the same classes are used for a Windows app, and a Web App, without any changes).  This is the proper way to develop applications.

AW
0
 
nuwebAuthor Commented:
wow thanks allot, whats the difference between command object, Dataset and DataAdapter?

also how would i do something similar to selecting records by id for instances in classic asp i would have in my sql select statement SELECT * from users where User_ID = " & strCurrentID & "


i've got things like pretty nailed down

<script language="VB" runat="server">
   sub Page_Load(Sender as Object, e as EventArgs)
      'set up connection
      dim objConn as new OleDbConnection _
         ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=c:\inetpub\wwwroot\net\users.mdb")

      'open connection
      dim objCmd as OleDbDataAdapter = new OleDbDataAdapter _
         ("select * from tblUsers where ", objConn)

      'fill dataset
      dim ds as DataSet = new DataSet()
      objCmd.Fill(ds, "tblUsers")

      'select data view and bind to server control
      MyDataList.DataSource = ds.Tables("tblUsers"). _
           DefaultView
      MyDataList.DataBind()
    end sub
</script>
0
 
NetworkArchitekCommented:
Ok, a Command object is basically just for entering SQL commands, or what have you. It can hold parameter collections for stored procedures, etc. A dataset is like a "Recordset" on massive steroids. A dataset is basically an in memory relational database which supports primary keys, constraints, etc and is intrinsically tied to XML. A DataAdapter basically allows you to do Data-Binding and is what you use to fill DataSets and DataTables. So if a DataSet is a relational database, then a DataTable is a table in  that database (note, a datatable does NOT have to per se be part of a dataset).

As far as something like this:
>>
also how would i do something similar to selecting records by id for instances in classic asp i would have in my sql select statement SELECT * from users where User_ID = " & strCurrentID & "
>>

Well, if you say where I did a "SELECT * FROM ORDERS" You can just as easily do:

oCmd.CommandText = "SELECT CUSTNAME FROM ORDERS WHERE ORDERID = " & strOrderID ' if that was a string variable

CommandText basically accepts any kind of SQL statement (actually even more than that but that suffices for now). So I'll edit your's a little. Remember a DataAdapter is basically something that USES a Command object to do stuff, like databind (you can use it to support inserts and updates, etc)

<script language="VB" runat="server">
   sub Page_Load(Sender as Object, e as EventArgs)
      'set up connection
      dim objConn as new OleDbConnection _
         ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=c:\inetpub\wwwroot\net\users.mdb")

      'open connection
      dim objCmd as OleDBCommand = new OleDBCommand
      objCmd.Connection = objConn
      objCmd.CommandText =  "SELECT * from users where User_ID = " & "'" & strCurrentID & "'"      ' The single qoute usages depeds on how your database system deals with string data.

         ("select * from tblUsers where ", objConn)

      'fill dataset
      dim ds as DataSet = new DataSet()
      objCmd.Fill(ds, "tblUsers")

      'select data view and bind to server control
      MyDataList.DataSource = ds.Tables("tblUsers"). _
          DefaultView
      MyDataList.DataBind()
    end sub
</script>

Hope this helps.
0
 
NetworkArchitekCommented:
*** Woops, when I edited your code I left out the dataadapter. I changed your's. Here it is:


<script language="VB" runat="server">
   sub Page_Load(Sender as Object, e as EventArgs)
      'set up connection
      dim objConn as new OleDbConnection _
         ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=c:\inetpub\wwwroot\net\users.mdb")

      'open connection
      dim objCmd as OleDBCommand = new OleDBCommand
      objCmd.Connection = objConn
      objCmd.CommandText =  "SELECT * from users where User_ID = " & "'" & strCurrentID & "'"      ' The single qoute usages depeds on how your database system deals with string data.

         ("select * from tblUsers where ", objConn)

      'fill dataset
      dim ds as DataSet = new DataSet()
      dim objAdapter As New OleDBDataAdapter(objCmd)
      objAdapter.Fill(ds, "tblUsers")

      'select data view and bind to server control
      MyDataList.DataSource = ds.Tables("tblUsers"). _
          DefaultView
      MyDataList.DataBind()
    end sub
</script>
0
 
nuwebAuthor Commented:
i really appreciate you taking the time to explain a few things to me. i liked the demo clips that where available from http://www.learnvisualstudio.net. do you know if there are video tutorials on that site pertaining to the questions i have asked you?
0
 
NetworkArchitekCommented:
yeah, like I said before all of this stuff and much more is on that site. He has whole ADO.NET videos devoted to specific things like just a Dataset or just Command object, etc. Its very good.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now