如何跳过列表视图行? [英] How do skip a list view row?

查看:67
本文介绍了如何跳过列表视图行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

this is my code in saving listview items into the mysql database in c#... how can i skip a listview row if it has no data inserted on it? Im kind of lost as to where I am going to insert the If Statement .. Please anyone?

for (int cnt = 0; cnt <= lv1.Items.Count - 1; cnt++)
                    {
                        string query = "insert into results(sid,c_id)values('" + _studid + "','" + lv1.Items[cnt].SubItems[2].Text + "')";


                        conn.Open();
                        MySqlCommand cmd = new MySqlCommand(query, conn);
                        cmd.ExecuteNonQuery();
                        conn.Close();


                    }

推荐答案

跳过listview行可以通过将插入逻辑包含在如果条件:

Skipping a listview row can be done by enclosing your insert logic in an if condition:
if (!string.IsNullOrEmpty (lv1.Items[cnt].SubItems[2].Text)) {
    // insert logic comes here
}



话虽如此,我建议你不要打开你的通过简单地将ListView控件中的文本作为有效数据接受SQL注入的代码。 如果你不知道SQL注入是什么,请谷歌吧。



/ ravi


That being said, I recommend you don't open your code to SQL injection by simply accepting text in the ListView control as being valid data.  If you don't know what SQL injection is, please Google it.

/ravi


这篇关于如何跳过列表视图行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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