Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Description: An unhandled exception occurred during the execution of the current web request. Please review the
stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Source Error:
This means you need to specify a primary key in the DataSet object. You can do this from the GUI interface by right-clicking a column (in this case, probably rowid) and selecting Set Primary Key.
AZMatt
Star
10652 Points
1898 Posts
Re: Select Count Queries in gridview
Dec 27, 2012 03:04 PM|LINK
This means you need to specify a primary key in the DataSet object. You can do this from the GUI interface by right-clicking a column (in this case, probably rowid) and selecting Set Primary Key.
Matt
prontonet
Member
243 Points
484 Posts
Re: Select Count Queries in gridview
Dec 27, 2012 03:43 PM|LINK
hi,
i do have a primary key enabled. In the data set I do a preview on the query by right clickingbnd it works fine.
only time I get the error is when I bind OBJ to a gridview or datalist?
prontonet
Member
243 Points
484 Posts
Re: Select Count Queries in gridview
Dec 27, 2012 03:52 PM|LINK
hi,
i do have a primary key enabled. In the data set I do a preview on the query by right clickingbnd it works fine.
only time I get the error is when I bind OBJ to a gridview or datalist?
rimagandhi
Participant
1589 Points
512 Posts
Re: Select Count Queries in gridview
Dec 28, 2012 03:15 AM|LINK
You can show the count like this
SQLDataAdapter da = new SQLDataAdapter("SELECT COUNT(*) FROM table_name");
Dataset ds = new Dataset();
da.Fill(ds);
lblNoofrecords.Text = ds.Tables[0].Rows.Count.ToString();
Regards
Rima Gandhi.
Software Developer.
arunabathan
Member
730 Points
236 Posts
Re: Select Count Queries in gridview
Dec 28, 2012 05:34 AM|LINK
Hi,
Please try below code.
And Business Layer
[System.ComponentModel.DataObjectMethod( System.ComponentModel.DataObjectMethodType.Select )] public DataTable GetFollowUpRecords( int startRowIndex, int maximumRows, string sortExpression, string param1, Int64 param2, bool param3 ) { using( sqlCommand = Dbase.GetCommand( Procs.StoreProce.ToString(), CmdType.StoredProcedure ) ) { if( sortExpression.Equals( string.Empty ) ) { sortExpression = "[FollowUpDate] ASC"; } AddParameter( "DepartmentId", param2 ); AddParameter( "Department", param1 ); AddParameter( "Active", param3 ); AddParameter( "sortexp", sortExpression ); AddParameter( "startRowIndex", startRowIndex ); AddParameter( "maximumRows", maximumRows ); AddParameter( "recordCount", recordCount ); sqlCommand.Parameters["@recordCount"].Direction = ParameterDirection.Output; ds = Dbase.GetDbaseDataSet( sqlCommand ); GetParameter( "recordCount", out recordCount ); } return ds.Tables[0]; } public int GetCount( string param1, Int64 param2, bool param3 ) { return recordCount; }Thanks&Regards,
Arunabathan.G
prontonet
Member
243 Points
484 Posts
Re: Select Count Queries in gridview
Dec 29, 2012 09:48 PM|LINK
perhaps more that what I need so I make a more simple explanation.