Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to validate if a column has the same data. In my database I have a column named SaleID which is a primary key and another called WorkqueueID which tells you which queue the Sale is in. I want to validate if the WorkqueueIDs are the same but nothing happens. I iterate through a gridview which is populated from an excel sheet into a form to get the Workqueue IDs and compare them with the ones in the database. Below is my code. Can anyone advise what I did wrong?

SQL
Select COUNT (DISTINCT S.WorkQueueID) from crm_Sale S
where SaleID

C#
DataTable1TableAdapter Da = new DataTable1TableAdapter();
                int Gridviewcount = 0;
                bool returnval = false;
                int Count = 0;

                try
                {
                    Gridviewcount = dgrvInfo.RowCount;
                    for (int c = 0; c < Gridviewcount; c++)
                    {
                        WorkQueueId = Convert.ToInt32(dgrvInfo.Rows[c].Cells[11].Value.ToString());
                        Count = Convert.ToInt32(Da.GetData(WorkQueueId));

                        
                    }

                    if (Count < 1)
                    {
                        returnval = true;
                    }

                    else
                    {
                        returnval = false;
                    }

                }


                catch (Exception)
                {
                    returnval = false;

                }
                return returnval;
            }
Posted
Updated 24-May-13 2:58am
v3
Comments
govardhan4u 24-May-13 7:16am    
Be simple. Do you want to check if all WorkqueueID's are similary to SaleID's?
Maciej Los 27-May-13 2:40am    
Please, be more specific and provide more details (example data, expected output).

On the first look, your query is wrong!

1 solution

Dear Friend,

What all that i have gathered from your question, I guess that you want to compare the WorkQueueIDs from the grid and from the DB table whether they are matching or not. With your method there is a tradeoff that you have to run a nested loop which means that No of rows in GridView multiplied by No. of Rows from the DataBase Table. So there is one easier comparison you can do with the following method:-

**Run a loop on the gird view and collect all the WorkQueueIDs as comma separated values and pass the same as SQL parameter to a procedure that will check that what all workQueueIds not matching with the param values are present in the Database.

If the result set comes greater than one then there you can give a prompt to user and returns from the function or if the result st comes less than 1 or zero then you can successfully returns from your function.

How to use the result from the procedure, it totally depends on you.

Please don't forget to mark this as your answer if it helps you out.

Thanks & Regards

Varun Sareen
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900