Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sample code to edit/add Access Database? 1

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
Anybody have a sample web page I could look at that can display current records from an Access database and give the option to add or edit records?

I'm totally stuck on this. I have code to successfully display my data in a datagrid, but for the life of me can't figure out how to edit or add records.

Help is much appreciated.

Thanks,

Mark
 
be more specific and don´t ask for someone to give you all the work.


You can use

Dim oCommand = New OleDb.OleDBCommand(Query,Cnn)

oCommand.ExecuteNonQuery()

where Query is your SQL to Add a record to your table o to Update your table.
and Cnn is the OleDBConnection

 
be more specific and [red]don´t ask for someone to give you all the work.[/red]

Daquita, first off welcome to the Tek-Tips site. I'm glad that you decided to post your first response to a thread however I don't wish a lecture on asking people to "GIVE ME ANSWERS". If you take a look at my profile you will find that I have responded to help others over 2700 times and to date received 452 votes. It is not necessary to be rude or abrupt. If a question is too vague it is sufficient to say so. Tek-Tips is a great forum because of the great people always willing to help others here. I hope you can be a part of that great tradition.

I'm not looking for anybody to do my work, only for some pointers as I am new to ASP.Net.

Through persistence I have managed to get code using a SQL INSERT to add to my database though this is not how I would like it.

I am using a datagrid to display the contents of an Access database. I've created columns to add buttons for Add, Edit and Delete however they don't seem to do anything. I read on GotASP.Net that these columns need to be converted to Template Columns but still no joy. My code is below. I have removed the Add/Edit buttons and am just trying to focus on the delete at the moment.

I'm using the beta of Visual Web Developer for my coding environment. I'm connecting to my database without a DSN.

My working code that fills my datagrid is:
Code:
Dim objconnection As OleDbConnection
        Dim objCommand As OleDbDataAdapter
        Dim strConnect As String
        Dim strCommand As String
        Dim DataSet1 As New DataSet
        strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;"
        strConnect += "Data Source=D:\Clients\fpdb\events.mdb;"
        strCommand = "SELECT date, time, type, subject FROM events ORDER BY events.date DESC;"
        objconnection = New OleDbConnection(strConnect)
        objCommand = New OleDbDataAdapter(strCommand, objconnection)
        objCommand.Fill(DataSet1, "events")
        DataGrid1.DataSource = DataSet1.Tables("events").DefaultView
        DataGrid1.DataBind()

And my datagrid code:
Code:
<asp:DataGrid id="DataGrid1" runat="server" CellSpacing="3" CellPadding="5" BorderColor="#1AD760" AutoGenerateColumns="False">
        <Columns>
            <asp:TemplateColumn>
                <ItemTemplate>
                    <asp:LinkButton runat="server" CausesValidation="false" CommandName="Delete" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateColumn>
            <asp:BoundColumn DataFormatString=" {0:d}" HeaderText="Date" DataField="date">
                <HeaderStyle font-bold="True" />
            </asp:BoundColumn>
            <asp:BoundColumn DataFormatString=" {0:t}" HeaderText="Time" DataField="time">
                <HeaderStyle font-bold="True" />
            </asp:BoundColumn>
            <asp:BoundColumn HeaderText="Event" DataField="type">
                <HeaderStyle font-bold="True" />
            </asp:BoundColumn>
            <asp:BoundColumn HeaderText="Attraction" DataField="subject">
                <HeaderStyle font-bold="True" />
            </asp:BoundColumn>
        </Columns>
        <HeaderStyle backcolor="#1AD760" forecolor="Black" />
    </asp:DataGrid>

If you or anyone can shed some light on why this is not working it would be appreciated.
 
you need to call the subs from the grid..

this is how I do it.

<asp:datagrid id="dgDetail" style="Z-INDEX: 127; LEFT: 1px; POSITION: absolute; TOP: 234px" runat="server" Width="702px" Font-Names="Verdana" Font-Size="XX-Small" BorderColor="#E7E7FF" BackColor="White" OnUpdateCommand="dgDetail_Update" CellSpacing="-1" AutoGenerateColumns="False" CellPadding="2" BorderStyle="None" BorderWidth="1px" GridLines="Horizontal" OnItemCommand="DoInsert" OnEditCommand="dgDetail_Edit" OnDeleteCommand="dgDetail_Delete" AllowPaging="True" ShowFooter="True" OnPageIndexChanged="ChangePage" PageSize="5">



 
Thanks dvannoy. That article is exactly what I was looking for. I found another article last night that helped me to successfully turn a record on it edit mode (using subs like you suggested). I just have not figured out the parts to write the changes back. I'll read through that article but at at glance it looks like it will provide the answers I seek.

Thanks again.

I hope you find this post helpful.

Regards,

Mark
 
Thanks for the suggestion lanm. I will check it out at my local Barnes and Noble.

You are absolutely right about the datagrid. I was just a novice at regular ASP, and now that I am starting to learn ASP.Net I really like it but there is a lot more to learn it seems, even though the code you can write is often shorter. My head hurts from staring at it.

I hope you find this post helpful.

Regards,

Mark
 
Mark,

I had a question that is kind of off-topic. I am new to ASP.NET and web sites in general - only have a few limited projects under my belt.

I am just wondering that if I have a website on ASP.NET and the data from the website links to an MS-ACCESS file on the server. Now here is the question..

The data interface from the web back and forth will be saved / edited in the MS-Access tables.. but what if inside the MS-ACCESS file I have an ODBC link database that goes to an oracle data warehouse. I know this might sound really stupid, but if a user on the ASP.NET website requests info from the MS-ACCESS, and the MS-ACCESS then hits the ODBC link table, the MS-ACCESS will use the server's (or where the MS-ACCESS resides) permissions, ODBC-DNS, etc to gain access to that info.

So basically on the intranet I have an oracle table that links to an MS-ACCESS. If I run the MS-ACCESS on my desktop within the intranet - I need to setup the ODBC DNS for the data warehouse for the oracle. So if I have a website (doesn't have to be ASp.net but it is), is there special permissions for an Internet user on the website to be able to have MS-ACCESS grab that same data or will it just use the server's permissions.

Sorry if this is off-topic or confusing.
 
Legions,

I would suggest starting a new thread with your question so you get more eyes looking at it.

I believe the answer to your question is that the anonymous account used on the web site will need to have ready permissions on your SQL database.


I hope you find this post helpful.

Regards,

Mark
 
You may need to ask , "do I really need to be running access at all"? Why not have all your tables in Oracle.

Post as new thread...these guys will throw alot of ideas and solutions to you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top