locked
Anyone could help me please? RRS feed

  • Question

  • User180516418 posted
    <%@ Page Language="C#" AutoEventWireup="true" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <script runat="server">
    
        public class AccessDatabase
        {
            public int UpdateAccessData()
            {
    
    
    
                // The following doesn't work
    
    
                int rowAffected = 5;
                System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
                conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=../DB/DAA.mdb";
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ex; 
                }
                return rowAffected;
            }
        }
    
    </script>
    
        <title>Sure Scripts</title>
    
    </head>
    <body>
    
    <%
        AccessDatabase accessDatabase = new AccessDatabase();
        Response.Write(accessDatabase.UpdateAccessData().ToString());
    %>
    
    
    
    
    
    <!-- The following works
    -->
    
    
    
        <form id="surescriptform" runat="server">
    
        <!-- 
        <asp:AccessDataSource  
            ID="SureScripts" 
            runat="server" 
            DataSourceMode="DataSet" 
            DataFile="../DB/DAA.mdb"  
            SelectCommand="SELECT pharmacy, serial_no, control_no FROM Users ORDER BY pharmacy">
        </asp:AccessDataSource>
        <asp:GridView 
            ID="surescriptgridview" 
            runat="server" 
            AutoGenerateColumns="false" 
            DataSourceID="SureScripts">
            <Columns>
                <asp:BoundField HeaderText="Pharmacy" DataField="pharmacy" />
                <asp:BoundField HeaderText="Serial No" DataField="serial_no" />
                <asp:BoundField HeaderText="Control No" DataField="control_no" />
            </Columns>
        </asp:GridView>
    -->
    
        </form>
    </body>
    </html>
    Thursday, September 1, 2011 4:57 PM

Answers

  • User180516418 posted

    I figured it out. I used HttpContext.Current.Server.MapPath(........). Thanks everyone!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2011 1:07 PM

All replies

  • User-142667041 posted

    you code only open connextion to db? what are you trying to make apdate? if update you need add command ;)

    Thursday, September 1, 2011 11:38 PM
  • User180516418 posted

    I found the bug. In the connection string I need to put space between Data and Source instead of DataSource. It worked from local host, still didn't work after I published, . I just want to establish connection for now.

    Tuesday, September 6, 2011 10:25 AM
  • User180516418 posted

    I figured it out. I used HttpContext.Current.Server.MapPath(........). Thanks everyone!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2011 1:07 PM