Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 25th, 2003, 08:02 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default Using a calender control with XML to update a data

Guys,

I am trying to update a datagrid with vales from a XML document. When I execute the data the screen in blank.

What am i doing wrong

Here is my code: -

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>
<%@ Page Language="C#" Debug="true" %>

<html>
  <head>
    <title>Inserting calender and XML data</title>
  </head>
  <body>
    <form id="Form2" runat="server" method="post">
      <table id="Table1"
             style="Z-INDEX: 101; LEFT: 7px; POSITION: absolute; TOP: 7px"
             cellspacing="0" cellpadding="0" width="300" border="0">
        <tr>
          <td style="WIDTH: 681" colSpan="3">
            <asp:DataGrid id="dgNorthWind" runat="server"
                 width="479" Height="191" BorderColor="#CC9966"
                 BorderStyle="None" BorderWidth="1"
                 BackColor="white" CellPadding="4"
                 DataKeyField="EmployeeID" AutoGenerateColumns="False">
            <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66" />
            <ItemStyle ForeColor="#330099" BackColor="White" />
            <HeaderStyle Font-Bold="True"
                         ForeColor="#FFFFCC" BackColor="#990000" />
            <FooterStyle ForeColor="#330099" BackColor="#FFFFCC" />
            <columns>
              <asp:BoundColumn DataField="FirstName" HeaderText="First Name"/>
              <asp:BoundColumn DataField="LastName" HeaderText="Last Name"/>
              <asp:BoundColumn DataField="HireDate" HeaderText="Hire Date"/>
            </columns>
            <PagerStyle HorizontalAlign="Center"
                        ForeColor="#330099" BackColor="#FFFFCC" />
            </asp:DataGrid>
          </td>
        </tr>
        <tr>
          <td Style="WIDTH: 681; HEIGHT: 49" colSpan="2">
            <asp:Label id="Label1" runat="server"
                         Height="45" Width="480" BackColor="Maroon" Font-Bold="True"
                         ForeColor="#FFE0C0">
               By selected a record from the calender you will entr a value into the database.
            </asp:Label>
          </td>
        </tr>
        <tr>
          <td Style="WIDTH: 681" colSpan="3">
            <asp:Calendar id="calHire" runat="server" OnSelectionChanged="calHire_SelectionChanged"
                          BorderColor="#FFCC66" Height="153" Width="479" BackColor="#FFFFCC"
                          BorderWidth="1" ForeColor="#663399"
                          EnableViewState="False" ShowGridLines="True"
                          Font-Names="Veranda" Font-Size="8pt">
              <TodayDayStyle ForeColor="White" BackColor="#FFCC66" />
              <SelectorStyle BackColor="#FFCC66" />
              <NextPrevStyle Font-Size="9pt" ForeColor="#FFCC66" />
              <DayHeaderStyle Height="1" BackColor="#FFCC66" />
              <SelectedDayStyle Font-Bold="True" BackColor="#CCCCFF" />
              <TitleStyle Font-Size="9pt" Font-Bold="True"
                          ForeColor="#FFFFCC" BackColor="#990000" />
              <OtherMonthDayStyle ForeColor="#CC9966" />
            </asp:Calendar>
          </td>
        </tr>
        <tr>
          <td Style="WIDTH: 681" colSpan="3">
            <asp:Label id="lbError" runat="server" ForeColor="Red" />
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>

<script language="c#" runat="server">
OleDbConnection objConnection;
OleDbDataAdapter objAdapter;
DataSet objDataSet;


private void Page_Load(object sender, EventArgs e)
{
  String strConnection="Provider=Microsoft.Jet.OleDb.4.0; data source=c:\\test\\Northwind.mdb;";
  objConnection = new OleDbConnection(strConnection);

  String strSQL = "SELECT EmployeeID, LastName, FirstName, HireDate FROM Employees";
  objAdapter = new OleDbDataAdapter(strSQL, objConnection);

  OleDbCommandBuilder cb = new OleDbCommandBuilder(objAdapter);

  if (!Page.IsPostBack)
    FillGridData();

}

private void FillGridData()
{
  objDataSet = new DataSet("Employees");

  objAdapter.Fill(objDataSet);

  dgNorthWind.DataSource = objDataSet.Tables[0].DefaultView;

  dgNorthWind.DataBind();
}

private void calHire_SelectionChanged(object sender, EventArgs e)
{
  if(calHire.SelectedDate <= DateTime.Today)
  {
    DataSet dsTemp = new DataSet();

    dsTemp.ReadXml("C:\\test\\Employees.xml");

    DataRow r = dsTemp.Tables[0].NewRow();

    r["LastName"] = "Ferracchiati";
    r["FirstName"] = "Fabio C.";
    r["HireDate"] = Convert.ToDateTime(calHire.SelectedDate);

    dsTemp.Tables[0].Rows.Add(r);

    objAdapter.Update(dsTemp, "EMPLOYEE");

    FillGridData();
   }
   else
    Response.Write("Hire Dates in the future cannot be selected so kiss my ass you booty shaker");
    Response.End();
}
</script>

Adz

__________________
Adz - Learning The J2EE Ways.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calender control - How to open next page? paragdongre ASP.NET 2.0 Basics 3 November 5th, 2007 01:28 AM
Using calender control in datagrid bala24 General .NET 0 June 5th, 2006 02:40 AM
problem regarding calender control CsharpHelp C# 0 November 14th, 2005 07:47 AM
Calender control anita VB How-To 4 December 12th, 2004 03:10 PM
UserForm - Calender control venky Excel VBA 1 October 27th, 2004 03:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.