Wrox Programmer Forums
|
BOOK: Beginning C# 2005 Databases
This is the forum to discuss the Wrox book Beginning C# 2005 Databases by Karli Watson; ISBN: 9780470044063
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 2005 Databases 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 March 2nd, 2007, 09:02 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ex 401 isnt working right

Code:
        private void weatherRecordDataGridView_RowLeave(object sender,
            DataGridViewCellEventArgs e)
        {
            try
            {
                // Get Row
                DataRowView rowView = 
                    weatherRecordDataGridView[e.ColumnIndex, e.RowIndex]
                    .OwningRow.DataBoundItem as DataRowView;
                if (rowView != null)
                {
                    Database1DataSet.WeatherRecordRow row = 
                        rowView.Row as Database1DataSet.WeatherRecordRow;

                    // Check values and assign defaults
                    if (row.IsNull("RecordedDate"))
                    {
                        row.RecordedDate = DateTime.Today;
                    }
                    if (row.IsNull("Temp"))
                    {
                        row.Temp = 32.0M;
                    }
                    if (row.IsNull("Summary"))
                    {
                        row.Summary = "Average";
                    }
                    if (row.IsNull("Cloudy"))
                    {
                        row.Cloudy = false;
                    }
                    if (row.IsNull("RecorderNo"))
                    {
                        row.RecorderNo = -1;
                    }

                    // Refresh display
                    weatherRecordDataGridView.Refresh();
                }
            }
            catch (IndexOutOfRangeException)
            {
                // Row was deleted - Ignore
            }
        }


My code matches the book except some different wording but it doesnt work the same as the one in the download. It only inserts defaults if I click on the cloudy check box. If I just skip over it the program throws an NoNull error.

 
Old March 2nd, 2007, 11:05 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to VictorQ
Default

Quote:
quote:Originally posted by xlr8
My code matches the book except some different wording but it doesnt work the same as the one in the download. It only inserts defaults if I click on the cloudy check box. If I just skip over it the program throws an NoNull error.
Have you checked the settings for the "Cloudy" field in the "WeatherRecord" table you created? Perhaps you set the field to allow nulls but you treat it in your code as a no null field. Also, did you add the event handler to the DataError event of the DataGridView control? (page 121, step 11).

Good luck! :)

P.S.: Hey I think I found an explanation for your problem. Check page 122 on the problems of null values being created for fields with no value specified once the row is inserted (even though you explicitly set the field to not allow nulls . That could be a problem espcially with boolean fields (such as "Cloudy" in this particular case)). There you can find a way to fix the issue directly in the data set designer.
 
Old March 2nd, 2007, 12:09 PM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yah, I read that as well and even opened the DataSet Designer and set the default to False in the properties box. My confusion is that the event doesnt seem to fire unless I click on that check box. I put a breakpoint on the entry to teh Try block and tabbed past the end of the row but it throws the NoNull error.. I did put the error event in as well but it doesnt act like its firing either...

:confused:

Thx :)

 
Old March 2nd, 2007, 08:34 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to VictorQ
Default

I finally had the chance to try it again for my self and I got a similar behavior... No default values added if "Cloudy" is not checked... The only way to get default values added with "Cloudy" unmarked is, as the book says, checking it and then unchecking it again... that way the row will get added and default values will be assigned. Strange indeed.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript isnt work well on my aspx page msbsam ASP.NET 2.0 Professional 1 July 11th, 2008 08:00 AM
How to provide custom error page for 401 Errors naganirangen Apache Tomcat 3 February 9th, 2008 01:54 PM
can anyone see why this isnt working? ldavis Classic ASP Databases 0 January 5th, 2006 10:59 PM
Unexplained 401 errors sejhemming VS.NET 2002/2003 0 April 20th, 2005 07:44 AM
The request failed with HTTP status 401: Unauthori CBS .NET Web Services 3 November 30th, 2004 10:07 AM





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