form not passing data

Posted on 2011-10-19
Last Modified: 2013-12-16
I have missed something with these two pages.
The front end loads and gives no error - the submit button does not give results
The data is not transferred to the table. - I do not usually code in asp, doing this as a favor so any help is gratefully appreciated.

Front End
<%@ Page Language="c#" AutoEventWireup="false" CodeBehind="rainEvents.aspx.cs" Inherits="FileUpload.WebForm1"
    Src="rainEvents.aspx.cs" %>

<body ms_positioning="GridLayout">
    <br />
    <form id="Form1" method="post" runat="server" enctype="multipart/form-data"><br />
     Enter the Collection Date: <asp:TextBox ID="collection" runat="server" />
    <br /> <br />
    Enter the Site Code: (M,E,P or B)<asp:TextBox ID="site" runat="server" /><br /> <br />
    Enter the Bottle Number: <asp:TextBox ID="bottleNumber" runat="server" /><br /> <br />
    Enter the Bottle_type: (T or P) <asp:TextBox ID="bottleType" runat="server" /><br /> <br />
    Enter the Bottle Rep (A or B): <asp:TextBox ID="bottleRep" runat="server" /><br /> <br />
    Enter the Date Deployed: <asp:TextBox ID="deployed" runat="server" /><br /> <br />
    Enter the Collection Time: <asp:TextBox ID="collectionTime" runat="server" /><br /> <br />
    Enter the UWF User ID: <asp:TextBox ID="userId" runat="server" /><br /> <br />
    Enter the tareWGT: <asp:TextBox ID="tareWgt" runat="server" /><br /> <br />
    Enter the totalWGT: <asp:TextBox ID="TotalWgt" runat="server" /><br /> <br />
    Enter the Sample WGT: <asp:TextBox ID="sampleWgt" runat="server" /><br /> <br />
    Enter the Ph: <asp:TextBox ID="pH" runat="server" /><br /> <br />
    Enter the Notes: <asp:TextBox ID="Notes" runat="server" /><br /> <br />
    Is the sample Contaminated? <asp:CheckBox ID="contaminated" runat="server" /><br /> <br />
    <br />
    <asp:Button ID="cmdSend" runat="server" Text="Send" />
    <br />
    <br />

Open in new window

Back End
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data;
using System.Data.OleDb;

namespace FileUpload

    public class WebForm1 : System.Web.UI.Page
        private const string MDBFILE = "~/hgdeposition/App_Data/hgweb.mdb";

        protected Label lblFile;
        protected HtmlInputFile filMyFile;
        //protected System.Web.UI.WebControls.Label lblInfo;

        protected System.Web.UI.WebControls.TextBox collection;
        protected System.Web.UI.WebControls.TextBox site;
        protected System.Web.UI.WebControls.TextBox bottleNumber;
        protected System.Web.UI.WebControls.TextBox bottleType;
        protected System.Web.UI.WebControls.TextBox bottleRep;
        protected System.Web.UI.WebControls.TextBox deployed;
        protected System.Web.UI.WebControls.TextBox collectionTime;
        protected System.Web.UI.WebControls.TextBox userId;
        protected System.Web.UI.WebControls.TextBox tareWgt;
        protected System.Web.UI.WebControls.TextBox TotalWgt;
        protected System.Web.UI.WebControls.TextBox sampleWgt;
        protected System.Web.UI.WebControls.TextBox pH;
        protected System.Web.UI.WebControls.TextBox Notes;
        protected System.Web.UI.WebControls.CheckBox contaminated;
        protected System.Web.UI.WebControls.Button cmdSend;
        override protected void OnInit(EventArgs e)

        private void InitializeComponent()
            this.Load += new System.EventHandler(this.Page_Load);
            this.cmdSend.Click += new System.EventHandler(this.cmdSend_Click);

        private void Page_Load(object sender, System.EventArgs e)

        // Processes click on our cmdSend button
        private void cmdSend_Click(object sender, System.EventArgs e)

       // Generates database connection string
        private string GetConnectionString()
            return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(MDBFILE) + ";";

        // Writes file to the database
        private int WriteToDB(DateTime collection, string site, string bottle_number, string bottlerep, DateTime deploy, DateTime myDateTime, string UserId_uwf,  int tareWGT, int totalWGT, int sample_ml, int ph, string Notes,  bool contaminated)
            int nFileID = 0;

            // Create connection
            OleDbConnection dbConn = new OleDbConnection(GetConnectionString());

            // Create Adapter
            OleDbDataAdapter dbAdapt = new OleDbDataAdapter("SELECT * FROM rainEventsTest", dbConn);

            // We need this to get an ID back from the database
            dbAdapt.MissingSchemaAction = MissingSchemaAction.AddWithKey;

            // Create and initialize CommandBuilder
            OleDbCommandBuilder dbCB = new OleDbCommandBuilder(dbAdapt);

            // Open Connection

            // New DataSet
            DataSet dbSet = new DataSet();

            // Populate DataSet with data
            dbAdapt.Fill(dbSet, "rainEventsTest");

            // Get reference to our table
            DataTable dbTable = dbSet.Tables["rainEventsTest"];

            // Create new row
            DataRow dbRow = dbTable.NewRow();

            // Store data in the row
            //dbRow["pKey"] = AutoNumber;
            dbRow["collection_date"] = collection.Date.ToShortDateString();
            dbRow["Site"] = site;
            dbRow["bottle_number"] = bottle_number;
            dbRow["bottlerep"] = bottlerep;
            dbRow["date_deployed"] = deploy.Date.ToShortDateString();
            dbRow["Collection_time"] = myDateTime.ToString("t");
            dbRow["UserId_uwf"] = UserId_uwf;
            dbRow["tareWGT"] = tareWGT;
            dbRow["totalWGT"] = totalWGT;
            dbRow["sample_ml"] = sample_ml;
            dbRow["ph"] = ph;
            dbRow["Notes"] = Notes;
            dbRow["contaminated"] = contaminated;

            // Add row back to table

            // Update data source
            dbAdapt.Update(dbSet, "rainEventsTest");

            // Get newFileID
            if (!dbRow.IsNull("FileID"))
                nFileID = (int)dbRow["Pkey"];

            // Close connection

            // Return FileID
            return nFileID;

Open in new window

Question by:Tagom
    LVL 11

    Expert Comment

    There is no code in the cmdSend button click event

    Author Comment

    Do you have an example of what should go there by chance.
    I have a long extensive example but it is difficult for me to follow.
    LVL 11

    Expert Comment

    What do you want to do when the button is clicked?

     private void cmdSend_Click(object sender, System.EventArgs e)
               ' you need to do what ever you want here
    LVL 9

    Accepted Solution

    you need to code your validation and business class method in cmdSend_Click method.

    Something like this:

     private void cmdSend_Click(object sender, System.EventArgs e)
               //create some business object and set data to its properties
               Order newOrder = new Order();
               newOrder.Collection = collection.Text; //sets collection text box's value
               newOrder.Notes = Notes.Text;

               //Send this business object to Data access logic for some other business logic class for further processing

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now