473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Strange error

I have an application with MDI windows. The following code generates an
error on some tables on "ad.Fill(ds);" if the table has data and needs to be
cleared the first time. The second time the table is cleared there is no
error. This problem only occurs if the MDI window is maximized and does not
occur when the window is normal.

If I remove the check for data in the table and just clear the table the
error occurs the first time the data is loaded if the window is maximized.
If the window is normal size there is no error ever. If the windows is
maximized and the error occurs refreshing the data (calling the function a
second time) clears the error and works fine.

Since ad.Fill is an MS function I am clueless on where to look, any
suggestions? I can not understand what the size of the windows has to do
with anything.

Error message: (basically the data from the SQL is missing one record and
one record exists twice)
{"Failed to enable constraints. One or more rows contain values violating
non-null, unique, or foreign-key constraints." }

Code:
public static bool LoadData(Form frm, SqlConnection cn, SqlDataAdapter ad,
DataSet ds, string msg)
{
bool RetVal = false;

if(ds == null) return RetVal;

try
{
frm.Cursor = Cursors.WaitCursor;

Utils.MiscFuns.OpenConnection(cn, true, "RAMS");

bool clearFlag = false;
foreach(System.Data.DataTable dt in ds.Tables)
{
if(dt.Rows.Count > 0)
{
clearFlag = true;
break;
}
}

if(clearFlag)
ds.Clear();

ad.Fill(ds);

RetVal = true;
}
catch(Exception ex)
{ Utils.frmError.ShowError(msg, ex); }
finally
{
frm.Cursor = Cursors.Default;
cn.Close();
}

return RetVal;
}
Regards,
John
Nov 16 '05 #1
4 931
Hi John,

Is the dataset a strong typed dataset? Are there any constraints like
primary key or foreign key defined in the dataset? Additionally, before you
clear the dataset, if you call the dataset's AcceptChanges method, will
this help?

Normally, a windows's state (Maximized or normal) won't impact the a
dataset. Is there any controls which are data bound to the dataset? If
winodw's state is changed, is it possible that these controls's values are
also changed?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 16 '05 #2
Wow that worked, I'm amazed... Thanks!

Someday I will even figure out what adding AcceptChanges before a Clear has
to do with the screen being minimized or maximized. I can sort see where
accepting changes would cause the data set to be more stable but should this
not occur when the clear is called?

In regards to the other questions.:

1) Yes it's strongly typed.
2) Yes it has a constraint which is what generates the error. If you look
at the datagrid what seems to happen in the dataset is one record from the
SQL query is lost and another record is duplicated.
3) The dataset is bound to a datagrid. I would not think the datagrid would
know if the screen was maximized. It's docking is set to full for the area
it occupies and that does not change.

Regards,
John

Nov 16 '05 #3
Hi John,

We had better to call AcceptChanges before clear method, especially, the
dataset is bound to some control like text box and datagrid. This can
ensure the data in dataset are removed safely.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 16 '05 #4
Ok, Thanks,
John
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
0
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
6
by: Gary | last post by:
I have an application that has been working just fine for a couple of years. It queries a SQL database and returns some formatted data back to the client. I have a new client, who has a larger...
5
by: Nathan Sokalski | last post by:
When I view my index.aspx page any time after the first time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize)...
0
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
1
by: JoReiners | last post by:
Hello, I have a really strange problem. I'm unable to figure it out on my own. I parse very simple xml documents, without any check for their form. These files look very similar and are encoded...
11
by: Mike C# | last post by:
Hi all, I keep getting a strange error and can't pin it down. The message is: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's...
3
by: Shelly | last post by:
I am encountering two strange problems. First one: I get a "server misconfiguration error", but only sometimes. It occurs on the first screen that accesses the database on a submit. This error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.