如何制作包含datagridviews值的字符串 [英] How to make string which contains datagridviews value

查看:77
本文介绍了如何制作包含datagridviews值的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Gridviews Column中存在任何一个值,我的代码将检查表中的可用数据,它将返回可用值。

但是有一些错误,所以为什么它只检查gridview中第一个值。

代码如下

ok这里是完整代码...



Here Is my Code to check available data in table if there exist any one value of Gridviews Column it will return the available value.
But there is somthing wrong so why it check only one value which is first in gridview.
The Code is as below
ok Here is the Full Code...

private void SureToDeleteBill() // Cheking For There Is No Imei in Bill Which Is Sold
        {
            
                try
                {
                    for (int i = 0; i <= dataGridView2.Rows.Count-1; i++)
                    {
                        // check either imei is sold or available in Imei Sold table
                        cs.Open();
                        cmd = new OleDbCommand("select * from tblsIMEI where IMEI = @a0", cs);
                        cmd.Parameters.AddWithValue("@a0", dataGridView2.Rows[i].Cells[1].Value.ToString());
                        dr = cmd.ExecuteReader();
                        if (dr.Read())
                        {
                            string msg;
                            msg = dr["IMEI"].ToString();
                            MessageBox.Show("Sorry !!\nYou Can Not DeleteBill !\n Sold IMEI :  ", "Sold IMEI", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            return;
                        }
                        else
                        {
                            DialogResult r = MessageBox.Show("Sure To Proceed?", "Delete Data", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (r == DialogResult.Yes)
                            {
                                DeleteFromtblPurchase();
                                DeleteFromtblIMEI();
                                DeleteFromPurchaseModel();
                                DeleteFromDealerBill();
                                MessageBox.Show("Record Delete Success!!", "Delete");
                                this.Close();
                            }
                            else
                            {
                                return;
                            }
                        }
                        cs.Close();
                    }
                    }
                
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Sure To Delete");
                }
                finally
                {
                    cs.Close();
                }
        }



请帮忙解决。


Please help to solve it.

推荐答案

好吧。 ..它不会编译。或者工作如果它。



让我们来看看你的控制结构:

Well...it isn't going to compile. Or work if it did.

Let's have a look at your control structures:
try
{
    for (int i = 0; i <= dataGridView2.Rows.Count-1; i++)
    {
        if (dr.Read())
        {
        }
        else
        {
        }
        else
        {
        }
    }
}
}

catch (Exception ex)
{
}
finally
{
}
}



所以,从中间开始,你有这个:


So, starting in the middle, you have this:

if (a) A;
else B;
else C;

那是什么?你不能有两个 else 子句用于相同的 if !那是错的,而且我不确定你在那里做什么...



暂时忽略它,(或假设你修复它)和 catch 不匹配 - 你那里有一个虚假的}。



现在让我们来看看如果(通过奇迹)它编译和工作会发生什么。

你在循环中打开连接。为什么?你也可以在循环中关闭它。并在最后块...



无论你走进的方式如果结果相同:返回或完全关闭表单!



坦率地说,这看起来像你从互联网上随机抓取代码行并通过它们在一起,希望它能神奇地工作。如果没有,请把它塞进这里,希望我们能为你修好。

开发不会那样:这是你在学校里可以学习的为数不多的科目之一必须考虑你想要做什么。在那里,它是对现实世界的一个很好的介绍 - 但如果你不开始在这里思考,你就不会在学期结束时翻转汉堡。你在现实世界中做...:笑:

What is that? you can't have two else clause for the same if! That's wrong, and I'm not sure what you are trying to do there...

Ignore that for a moment, (or assume you fixed it) and the catch doesn't match with the try - you have a spurious "}" in there.

Now let's look at what happens if (by a miracle) it did compile and work.
You open the connection in the loop. Why? You also close it in the loop. And in the finally block...

And whichever way you go in the if the result is the same: return or close the form completely!

Frankly, this looks like you randomly grabbed lines of code from the internet and through them together, hoping it would magically work. And when it didn't, stuffed it up here in the hope we would fix it for you.
Development doesn't work like that: it's one of the few subjects you can study at school where you have to think about what you are trying to do. In that, it's a great introduction to the real world - but if you don't start to think here, you don;t end up flipping burgers by the end of term. You do in the real world...:laugh:


你应该使用
continue; 

而不是

return;

: - )


这篇关于如何制作包含datagridviews值的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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