Link to home
Start Free TrialLog in
Avatar of Tagom
Tagom

asked on

need helpwith a form

I have been asked to create a small form that can be used by our data entry clients. This should be in asp.net -
The form has 4 columns
name, address, delivered (Boolean ), date
I already have the connection to the database done and have been able to pull information but have not been successful at the form - in all honesty - cant even figure out how to begin other than the connections and retrieval.

Could someone please help me get started - This is a volunteer organization helping pregnant teens.

Thank you in advance.
Avatar of bloodtrain
bloodtrain
Flag of Canada image

Will you be calling stored procedures to insert the data into the database?
Avatar of Tagom
Tagom

ASKER

If that is the easiest way - the database is access (which I am not really familiar with writing stored procedures in - I usually work in mssql
This is a new and challenging project for me - however it is for a good cause :)
Since you're using MS Access, I don't think you can create stored procedures - I never have anyway. Here is some .Net C# code that should connect to the DB and insert data:

protected void btnSubmit_Click(object sender, EventArgs e)
{
        OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + Server.MapPath("~\\App_Data\\teens.mdb'") + "; Persist Security Info=True");
        try
        {
            myConnection.Open();
            string sqlCmd = "INSERT INTO teens (name, address, delivered, date) VALUES ('Lisa', '123 Somewhere', 1, '08/07/2011')";
            
            OleDbCommand insertCmd = new OleDbCommand(sqlCmd, myConnection);
            insertCmd.ExecuteNonQuery();
            myConnection.Close();            
        }
} 

Open in new window

Avatar of Tagom

ASKER

Thank  you very much bloodtrain - I think I did not explain well enough -
That part I have - what I am having trouble figuring out is how to create a form accessible via the website that will allow a teen to register with us....
So I need to write the webbase form that will map the input boxes to the correct variable which will be stored in the database -
I know that in the part of your code it I would have to replace 'Lisa' with @name - this is the part I am stuck with! and then to make sure it submits and inserts.

ASKER CERTIFIED SOLUTION
Avatar of bloodtrain
bloodtrain
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tagom

ASKER

Thank you so much! I will test it and let you know if it blows up!
Avatar of Tagom

ASKER

I must apologize for taking so long to get back to this project!
I used the code mentioned above - however I am getting an error
ERROR: CS1010: Newline in constant
CODE:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void btnSubmit_Click(object sender, EventArgs e)
    {
       		
		OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + Server.MapPath("Data Source = \\mydomain\\outreachStaff\\home\\Southside\\database\\Teens.mdb"") + "; Persist Security Info=True");
        try
        {
            myConnection.Open();
            string sqlCmd = "INSERT INTO Teens (name, address, delivered, date) VALUES ('Lisa', '123 Somewhere', 1, '08/07/2011')";

            OleDbCommand insertCmd = new OleDbCommand(sqlCmd, myConnection);
            insertCmd.ExecuteNonQuery();
            myConnection.Close();
        }
        catch (Exception ex)
        {
            // Handle the error
			
            // Either log it in a file or email yourself (ex.toString())
        }

    } 

}

Open in new window

Avatar of Tagom

ASKER

could not get code to work due to connectivity issues - however code did compile.