J
John J. Hughes II
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
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