Linking a text box and/or a list box to an Access table's column.

Discussion in 'ASP .Net' started by ryan.d.rembaum@kp.org, Aug 4, 2005.

  1. Guest

    I have posted q couple questions about databinding, but figured I'd
    simplify my questions and see if what I want to do is even possible.

    I have a database C:\mydatase.mdb
    In it there is a table tbleCategory
    In that table are two fields fldCat and fldID.

    I know how to use ASP and ADO to update a database at a click of a
    button by sending dynamically created SQL to the database, but it seems
    like there are new methods out there that would be better in that the
    database would be aware of collisions (two users modifing data in a
    field at the same time via a web page). Is this one of the powers that
    databinding offers. If so, can I implement it. I have tried RDS and
    ..dot and get nothing. Not even an error with the code I am trying.

    If I want to bind the Category name column in my database to a text
    field, and allow the user to scroll through each record and make
    changes, can this be done? Or should I simply continue to use basic
    ASP? If it can be done, given the example below, what would the code
    look like. Is it simple?

    Here is code I tried with the NorthWind database that returned NO
    values from the table:

    Thanks,

    <%@ Import Namespace="System.Data.OleDb" %>

    <script runat="server">
    sub Page_Load
    dim dbconn,sql,dbcomm,dbread
    dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
    source=" & server.mappath("C:/Program Files/Microsoft
    Office/Office/Samples/northwind.mdb"))
    dbconn.Open()
    sql="SELECT * FROM customers"
    dbcomm=New OleDbCommand(sql,dbconn)
    dbread=dbcomm.ExecuteReader()
    customers.DataSource=dbread
    customers.DataBind()
    dbread.Close()
    dbconn.Close()
    end sub
    </script>

    <html>
    <body>

    <form runat="server">
    <asp:DataList
    id="customers"
    runat="server"
    cellpadding="2"
    cellspacing="2"
    borderstyle="inset"
    backcolor="#e8e8e8"
    width="100%"
    headerstyle-font-name="Verdana"
    headerstyle-font-size="12pt"
    headerstyle-horizontalalign="center"
    headerstyle-font-bold="True"
    itemstyle-backcolor="#778899"
    itemstyle-forecolor="#ffffff"
    footerstyle-font-size="9pt"
    footerstyle-font-italic="True">

    <HeaderTemplate>
    Customers Table
    </HeaderTemplate>

    <ItemTemplate>
    <%#Container.DataItem("companyname")%> in
    <%#Container.DataItem("address")%>, <%#Container.DataItem("city")%>
    </ItemTemplate>

    <FooterTemplate>
    Source: Northwind Database
    </FooterTemplate>

    </asp:DataList>
    </form>

    </body>
    </html>
     
    , Aug 4, 2005
    #1
    1. Advertising

  2. David Wier Guest

    Check out:
    http://aspnet101.com/aspnet101/aspnet/codesample.aspx?code=drtest2
    and this one shows how to update the db:
    http://aspnet101.com/aspnet101/aspnet/codesample.aspx?code=update

    This code is using SQL Server - but the concept is totally the same - just
    the connection info on getting to the database is different
    There are plenty of datareader examples with MS Access on the site
    (connecting to the database), if you need, also.

    David Wier
    http://aspnet101.com
    ASP Express - http://aspexpress.com

    <> wrote in message
    news:...
    > I have posted q couple questions about databinding, but figured I'd
    > simplify my questions and see if what I want to do is even possible.
    >
    > I have a database C:\mydatase.mdb
    > In it there is a table tbleCategory
    > In that table are two fields fldCat and fldID.
    >
    > I know how to use ASP and ADO to update a database at a click of a
    > button by sending dynamically created SQL to the database, but it seems
    > like there are new methods out there that would be better in that the
    > database would be aware of collisions (two users modifing data in a
    > field at the same time via a web page). Is this one of the powers that
    > databinding offers. If so, can I implement it. I have tried RDS and
    > .dot and get nothing. Not even an error with the code I am trying.
    >
    > If I want to bind the Category name column in my database to a text
    > field, and allow the user to scroll through each record and make
    > changes, can this be done? Or should I simply continue to use basic
    > ASP? If it can be done, given the example below, what would the code
    > look like. Is it simple?
    >
    > Here is code I tried with the NorthWind database that returned NO
    > values from the table:
    >
    > Thanks,
    >
    > <%@ Import Namespace="System.Data.OleDb" %>
    >
    > <script runat="server">
    > sub Page_Load
    > dim dbconn,sql,dbcomm,dbread
    > dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
    > source=" & server.mappath("C:/Program Files/Microsoft
    > Office/Office/Samples/northwind.mdb"))
    > dbconn.Open()
    > sql="SELECT * FROM customers"
    > dbcomm=New OleDbCommand(sql,dbconn)
    > dbread=dbcomm.ExecuteReader()
    > customers.DataSource=dbread
    > customers.DataBind()
    > dbread.Close()
    > dbconn.Close()
    > end sub
    > </script>
    >
    > <html>
    > <body>
    >
    > <form runat="server">
    > <asp:DataList
    > id="customers"
    > runat="server"
    > cellpadding="2"
    > cellspacing="2"
    > borderstyle="inset"
    > backcolor="#e8e8e8"
    > width="100%"
    > headerstyle-font-name="Verdana"
    > headerstyle-font-size="12pt"
    > headerstyle-horizontalalign="center"
    > headerstyle-font-bold="True"
    > itemstyle-backcolor="#778899"
    > itemstyle-forecolor="#ffffff"
    > footerstyle-font-size="9pt"
    > footerstyle-font-italic="True">
    >
    > <HeaderTemplate>
    > Customers Table
    > </HeaderTemplate>
    >
    > <ItemTemplate>
    > <%#Container.DataItem("companyname")%> in
    > <%#Container.DataItem("address")%>, <%#Container.DataItem("city")%>
    > </ItemTemplate>
    >
    > <FooterTemplate>
    > Source: Northwind Database
    > </FooterTemplate>
    >
    > </asp:DataList>
    > </form>
    >
    > </body>
    > </html>
    >
     
    David Wier, Aug 5, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Galli
    Replies:
    0
    Views:
    2,190
    Richard Galli
    Jun 25, 2003
  2. gerry
    Replies:
    0
    Views:
    570
    gerry
    Apr 24, 2004
  3. savvy
    Replies:
    1
    Views:
    495
    savvy
    Jan 18, 2006
  4. Gnarlodious
    Replies:
    4
    Views:
    17,712
    elizas
    May 5, 2010
  5. asil klin
    Replies:
    28
    Views:
    1,328
    Andreas Leitgeb
    Mar 5, 2011
Loading...

Share This Page