This is a migrated thread and some comments may be shown as answers.

Problem with Validation

1 Answer 71 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tooraj
Top achievements
Rank 1
Tooraj asked on 04 Apr 2011, 09:08 AM
Hello,
I have a gridview with 3 columns 2 of them constrained to be NoNullAllowed and one to be Primary Key.
I have written code in CellValidation and RowValidation to cancel the validation in some scenarios.
But there are situations in which the Exception for null or Primary key still occurs. i.e, After leaving a cell empty and clicking on header of a column. the situations are many and finally I turned off the constraints so the problem doesn't occur.
But after doing such an action, sometimes I encounter another problem: After making the cell empty and typing in it again Cell.Value or Cell.Text is null!
I strongly need an error-free powerful example of controlling null and dupplicate values.
PLEASE GUIDE ME.


Another question in my mind and is unsolved is that If i use SqlTransaction which encloses Update method of my adapter what will happen(suppose we have 3 added records)?
1. if update of record 2 fails then only record 2 is rolled back (record 1 is added).
2. Connection.Open and Close method executes for any INSERT Statement or once for all inserted records?
I want this one for all.

Thanks a lot, Tooraj Azizi.

1 Answer, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 04 Apr 2011, 01:14 PM
Hello Tooraj,

For the first problem for row & cell validation, a very basic example could be the following:
void radGridView1_RowValidating(object sender, RowValidatingEventArgs e)
{
    if (e.Row == null)
    {
        return;
    }
 
    if (e.Row is GridViewDataRowInfo || e.Row is GridViewNewRowInfo)
    {
    }
}
 
void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
    if (e.Row == null)
    {
        return;
    }
 
    if (e.Row is GridViewDataRowInfo || e.Row is GridViewNewRowInfo)
    {
    }
}

for the second part:
1. If you wrap multiple statements in a transaction and ANY item in that transaction fails, all of the actions in that transaction should rollback.
2. You can use a connection for multiple operations the order should be something like this: Open the connection, create a transaction, perform all insert/ updates there, commit / rollback changes and close the connection.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
Tags
GridView
Asked by
Tooraj
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or