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

R

ryan.d.rembaum

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>
 
D

David Wier

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top