Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 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 December 3rd, 2007, 07:50 AM
Authorized User
 
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default submitting form - object creation timing

using the flixon generator - when i submit a form, is the following order of events correct:

1. in code-behind:
protected void btnSubmit_Click(object sender, EventArgs e)
{
int result = Report.InsertReport(Convert.ToDateTime(Date.Text), Time.Text, Details.Text)
}

================================================== ===================
2. this goes to the Report.cs file:

public static int[] InsertReport(DateTime Date,
                                                 string Time,
                                                 string Details)
{
            int result
                result = SiteProvider.Report.InsertReport(new ReportsEntity(0,Date,Time,Details));
}


================================================== ====================
3. this then passes to the SqlReportProvider:

        public override int InsertReport(ReportsEntity report)
        {
            int result;
            try
            {
                using (SqlConnection cn = new SqlConnection(ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("up_ReportsAdd", cn);

                    cmd.Parameters.Add("@ReportID", SqlDbType.Int).Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@Date", SqlDbType.SmallDateTime).Value = Report.Date;
                    cmd.Parameters.Add("@Time", SqlDbType.Char).Value = Report.Time;
                    cmd.Parameters.Add("@Details", SqlDbType.NVarChar).Value = Report.Details;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cn.Open();

                    ExecuteNonQuery(cmd);
                    result = (int)cmd.Parameters["@tReportID"].Value;
                }
            }
            catch (SqlException e)
            {
                CommonFunctions.LogError(e.Message, (int)ErrorID.Report);
                result = -1;
            }
            return result;
        }



 
Old December 3rd, 2007, 09:06 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

yes, looks about right. i presume something isn't getting passed into the final sql part as expected??

stepping thro' the code should reveal the exact steps taken (F10/F11)

jimi

http://www.originaltalent.com
 
Old December 3rd, 2007, 10:13 AM
Authorized User
 
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi jimi. no, it all works ok, it's just that in the flixon-generated code examples, the code-behind passes to a method in the report class which then passes to another method in the same class. it is in this 2nd method that the entity is created. i seem to be missing out this step?

 
Old December 3rd, 2007, 12:12 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

forumuser,

hmmm, not sure really (whether i fully follow 100%). i do notice that you don't actually return any values from the 1st two methods, i.e. you set an int result to the method that's called but don't actually then return result. not sure if this is intentional or not.


jimi

http://www.originaltalent.com
 
Old December 3rd, 2007, 02:59 PM
Authorized User
 
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

no, the point was that in flixon-generated code, one overload of the InsertReport method calls another overload within the same class, Reports. it is the 2nd overload which creates the Report entity and passes it to the sqlprovider. my code misses out this step and simply creates the entity in the 1st method called in the Reports class, and passes it to the sqlprovider.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Submitting a form to a database nvillare Classic ASP Basics 2 January 27th, 2005 06:38 PM
form submitting cro_crx Pro PHP 5 January 25th, 2005 12:19 PM
Form Submitting cro_crx Beginning PHP 3 January 17th, 2005 01:30 PM
Submitting a form YuliaKupina Classic ASP Basics 3 June 24th, 2004 01:52 AM





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