如何验证列是否具有相同的数据 [英] How to validate if a column has the same data

查看:75
本文介绍了如何验证列是否具有相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证列是否具有相同的数据。在我的数据库中,我有一个名为SaleID的列,它是一个主键,另一个名为WorkqueueID,它告诉您Sale在哪个队列。我想验证WorkqueueID是否相同但没有任何反应。我遍历一个gridview,它从excel表填充到表单中以获取Workqueue ID并将它们与数据库中的ID进行比较。以下是我的代码。任何人都可以建议我做错了吗?



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?

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




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;
            }

推荐答案

亲爱的朋友,



什么全部我从你的问题中收集到的,我想你想要比较网格中的WorkQueueID和数据库表中是否匹配。使用您的方法需要进行权衡,您必须运行嵌套循环,这意味着 GridView中的行数乘以数据库表中的行数。因此,您可以使用以下方法进行更简单的比较: -



**在网格视图上运行循环并将所有WorkQueueID收集为逗号分隔值和将与SQL参数相同的方法传递给一个过程,该过程将检查数据库中是否存在与param值不匹配的所有workQueueIds。



如果结果集大于1,那么你可以向用户发出提示并从函数返回,或者如果结果st小于1或0那么你可以从你的功能中成功返回。



如何使用程序的结果,这完全取决于你。



请不要忘记将此标记为您的答案,如果它可以帮助您。



谢谢&问候



Varun Sareen
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


这篇关于如何验证列是否具有相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆