Avatar billede peterfyr Nybegynder
21. maj 2004 - 14:33 Der er 17 kommentarer

Opdateringsside fra Xml til Access-fil

Jeg har lavet en side hvor man kan opdatere oplysninger (altså ændre, slette osv)

Den henviser til en xml-fil, hvor oplysningerne ligger i.
Hvordan får jeg den til at hente det fra en access-fil?
Avatar billede overchord Nybegynder
21. maj 2004 - 15:21 #1
hvilken version af Access arbejder du med?
Avatar billede terry Ekspert
21. maj 2004 - 15:28 #2
Can yiu explain a little more please?
You have a "side" which I assume you mean WEB side? This side can update information and the result is written to an XML document.

Do you want to use Access instead of XM or do you want the XML document to read data from Access?
Avatar billede terry Ekspert
21. maj 2004 - 15:28 #3
instead of XM = instead of XML
Avatar billede peterfyr Nybegynder
21. maj 2004 - 16:45 #4
Yes, I have a Web Side, which can update information shown in a datagrid and written to an XML document.
Instead I want the datagrid to be written to an Access file.
How do I do that?
Avatar billede peterfyr Nybegynder
21. maj 2004 - 16:46 #5
Jeg har Access 2002 for Windows XP (Office XP)
Avatar billede terry Ekspert
21. maj 2004 - 17:37 #6
To wriet to an Access database from a web page requires the use of some programming language for example ASP/ASP.NET. You cant NOT write to an Access database which is on your local PC, from a web page unless of course the web page is also located on yur own local PC.
To write to an Access database from a web page DOES NOT require Access but it deos require that the WEB server supports Access.

I cant teach you how to use Access from a web page but I can give some links.

http://www.html.dk/tutorials/asp/lektion18.asp
http://www.w3schools.com/asp/default.asp
http://www.asp-dev.com/default.asp?page_menu_id=29&page=29
http://www.asp101.com/
Avatar billede peterfyr Nybegynder
21. maj 2004 - 17:41 #7
I know how to write to an Access database via ASP.NET Web Matrix.

There are problems when I want to update information in a datagrid based on an Access database, instead of an XML document.
Avatar billede peterfyr Nybegynder
21. maj 2004 - 17:43 #8
Do you want to see the code lines
Avatar billede terry Ekspert
21. maj 2004 - 17:53 #9
You can show your code but I dont think it is going to help very much. This category is Access and programming in ASP or what ever isnt really my hot spot.

Anyway, lets have a look at you rcode to see if we can understand what is going on, then we can decide what to do from there!
Avatar billede peterfyr Nybegynder
21. maj 2004 - 17:57 #10
Dim ObjConn As oledbConnection
Dim ObjRs As oledbDataReader
Dim ObjCmd As oledbCommand
Dim DBPos, Antal, i, SideAntal, TotalPris As Integer
Dim CheckOutDate as Date
Dim NyAntalSolgt As Integer
Dim SQLStr As string
Dim strRes, strConn, strSQL, strSti as string
Dim objDR as OledbDataReader

Sub Page_Load(sender as object, e as eventargs)
    If not Page.IsPostback Then
        EventData.DataSource = LoadMyCalendarData
        EventData.DataBind()
    End If
End Sub

Protected Function LoadMyCalendarData() As DataSet
    Dim sourceXML as String = Server.MapPath("MyCalendar.xml")
    If    ( Not File.Exists(sourceXML) ) Then
        Return Nothing
    End if

    Dim cachedDataSet as DataSet = Session("MyCalendarData")
    if ( Not cachedDataSet Is Nothing ) Then
      Return cachedDataSet
    End if

    Dim dataSet As DataSet = New DataSet()

    Try
      dataSet.ReadXml(sourceXML)
      Session("MyCalendarData") = dataSet
    Catch e As Exception
      ErrorMessage.Text = e.Message
      dataSet = Nothing
    End Try

    Return dataSet
End Function

Sub DEDR_Edit(sender as object, e as DataGridCommandEventArgs)
    EventData.EditItemIndex = CInt(E.Item.ItemIndex)
    EventData.DataSource = LoadMyCalendarData
    EventData.DataBind()
End Sub

Sub DEDR_Update(sender as object, e as DataGridCommandEventArgs)
    Dim dataSet as DataSet = LoadMyCalendarData
    Dim row as Integer = CInt(E.Item.ItemIndex)
    Dim EditText as textbox

    EditText = E.Item.FindControl("txtShortDesc")
    dataSet.Tables(0).Rows(row).Item("ShortDesc") = EditText.Text
    EditText = E.Item.FindControl("txtDetailDesc")
    dataSet.Tables(0).Rows(row).Item("DetailDesc") = EditText.Text
    EditText = E.Item.FindControl("txtEventDate")
    dataSet.Tables(0).Rows(row).Item("EventDate") = EditText.Text
    EditText = E.Item.FindControl("txtStartTime")
    dataSet.Tables(0).Rows(row).Item("StartTime") = EditText.Text
    EditText = E.Item.FindControl("txtEndTime")
    dataSet.Tables(0).Rows(row).Item("EndTime") = EditText.Text

    dataSet.WriteXML(Server.Mappath("MyCalendar.xml"))

    Session("MyCalendarData") = Nothing

    EventData.EditItemIndex = -1

    EventData.DataSource = LoadMyCalendarData
    EventData.DataBind()
End Sub

Sub DEDR_Cancel(sender as object, e as DataGridCommandEventArgs)
    EventData.EditItemIndex = -1
    Session("MyCalendarData") = Nothing
    EventData.DataSource = LoadMyCalendarData
    EventData.DataBind()
End Sub

Sub DEDR_Delete(sender as object, e as DataGridCommandEventArgs)
    Dim dataSet as DataSet = LoadMyCalendarData
    Dim row as Integer = CInt(E.Item.ItemIndex)

    dataSet.Tables(0).Rows(row).Delete

    dataSet.WriteXML(Server.Mappath("MyCalendar.xml"))

    Session("MyCalendarData") = Nothing

    EventData.EditItemIndex = -1

    EventData.DataSource = LoadMyCalendarData
    EventData.DataBind()
End Sub

Sub DEDR_Add(sender as object, e as EventArgs)
    Dim dataSet as DataSet = LoadMyCalendarData
    Dim newRow as DataRow
    newRow = dataSet.Tables(0).NewRow()
    newRow.Item("EventDate") = ""
    newRow.Item("ShortDesc") = ""
    newRow.Item("DetailDesc") = ""
    newRow.Item("StartTime") = ""
    newRow.Item("EndTime") = ""
    dataSet.Tables(0).Rows.Add(newRow)

    dataSet.WriteXML(Server.Mappath("MyCalendar.xml"))

    Session("MyCalendarData") = Nothing

    EventData.DataSource = LoadMyCalendarData
    EventData.DataBind()

    EventData.EditItemIndex = EventData.Items.Count - 1

    EventData.DataSource = LoadMyCalendarData
    EventData.DataBind()
End Sub
Avatar billede peterfyr Nybegynder
21. maj 2004 - 18:04 #11
and here is the HTML code:

<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:Label id="Errormessage" runat="Server"></asp:Label>
        <br />
        <asp:linkbutton id="LinkButton1" onclick="DEDR_Add" runat="Server" text="Opret ny vare"></asp:linkbutton>
        <br />
        <asp:datagrid id="Eventdata" runat="Server" OnCancelCommand="DEDR_Cancel" OnDeleteCommand="DEDR_Delete" OnUpdateCommand="DEDR_Update" OnEditcommand="DEDR_Edit" width="100%" autogeneratecolumns="false">
            <Headerstyle forecolor="White" backcolor="DodgerBlue" font-bold="true" />
            <ItemStyle backcolor="White" />
            <AlternatingItemStyle backcolor="Gainsboro" />
            <Columns>
                <asp:TemplateColumn HeaderText="Varenummer">
                    <ItemTemplate>
                        <%# DataBinder.Eval(Container.DataItem, "EventDate") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Textbox id="txtEventDate" size="25" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "EventDate") %>' />
                    </EditItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="Varenavn">
                    <ItemTemplate>
                        <%# Container.DataItem("ShortDesc") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Textbox id="txtShortDesc" size="25" runat="server" Text='<%# Container.DataItem("ShortDesc") %>' />
                    </EditItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="Varetype">
                    <ItemTemplate>
                        <%# Container.DataItem("DetailDesc") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Textbox id="txtDetailDesc" size="7" runat="server" Text='<%# Container.DataItem("DetailDesc") %>' />
                    </EditItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="Beskrivelse">
                    <ItemTemplate>
                        <%# Container.DataItem("StartTime") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Textbox id="txtStartTime" size="50" runat="server" Text='<%# Container.DataItem("StartTime") %>' />
                    </EditItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="Pris">
                    <ItemTemplate>
                        <%# Container.DataItem("EndTime") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Textbox id="txtEndTime" size="7" runat="server" Text='<%# Container.DataItem("EndTime") %>' />
                    </EditItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn>
                    <ItemTemplate>
                        <asp:linkbutton Commandname="Edit" Text="Edit" runat="Server" />
                        <asp:linkbutton Commandname="Delete" Text="Delete" runat="Server" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:linkbutton Commandname="Cancel" Text="Cancel" runat="Server" />
                        <asp:linkbutton Commandname="Update" Text="Update" runat="Server" />
                    </EditItemTemplate>
                </asp:TemplateColumn>
            </Columns>
        </asp:datagrid>
    </form>
</body>
</html>
Avatar billede terry Ekspert
21. maj 2004 - 18:12 #12
As I susppected, I dont really understand exactly what is happening.

You need to be able to read/write to an Access database before you can do anything. So I would suggest you make a very simple web application using the links I gave and go from there. It would take me hours if I were to try and convert your code for you.
You may also get further help in the ASP category
Avatar billede peterfyr Nybegynder
21. maj 2004 - 18:14 #13
Thank you
Avatar billede peterfyr Nybegynder
21. maj 2004 - 18:15 #14
I have tried to write to an Access database at the beginning of the code lines, but it doesn't help. But thanks anyway for the help
Avatar billede terry Ekspert
21. maj 2004 - 18:20 #15
I cant see anything which makes a connection to an Access dB, but then maybe its in some datacontrol or something.
Avatar billede overchord Nybegynder
23. maj 2004 - 02:18 #16
Har du proevet at importere dine eksisterende XML-filer til Access foerst og fremmest?
Derefter skal du have oprettet en connection til db'en som Terry siger. Strengt taget akn du bibeholde dine XML-filer som linkede objekter i databasen, hvor det eneste DB goer er at query forskellige samlinger af xml-filer.
Avatar billede terry Ekspert
27. maj 2004 - 11:01 #17
whats the status here peterfyr?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester