form not passing data

Posted on 2011-10-19
Medium Priority
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
  • 2
LVL 11

Expert Comment

ID: 37000810
There is no code in the cmdSend button click event

Author Comment

ID: 37000891
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

ID: 37004104
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

Accepted Solution

gery128 earned 2000 total points
ID: 37004842
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

809 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