l在运行时将数据从列表视图保存到数据库 [英] lsaving data from listview to database in runtime

查看:200
本文介绍了l在运行时将数据从列表视图保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时在列表视图中添加了项目,但无法将这些项目和子项目保存在数据库中,请帮助我给出正确的代码
谢谢

i hav add items in listview in runtime but not able to save those items and subitems in database pls help me giving right code
thank you

推荐答案



Hi,

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            Dim i, c As Integer
            Dim a, b As Integer
            i = ListView1.Items.Count - 1
            While i >= 0
                a = ListView1.Items.Item(i).Text
                b = ListView1.Items.Item(i).SubItems.Item(1).Text
                c = ListView1.Items.Item(i).SubItems.Item(2).Text

                Dim QUERY As String
                QUERY = "INSERT INTO stockinhand(stockcode,stocknamename,quantity)VALUES ('"+ a +"','" + b +"','" + c + "')"
                EXECUTEQUERY(QUERY)
                MsgBox("saved")
            End While
        Catch eEndEdit As System.Exception
            System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
        End Try


    End Sub



请像这样更改您的查询.
可能会对您有帮助.

问候
AR



Please change your query like this.
It might help you.

Regards
AR


我不是VB专家,但这是在C#中的实现方法

I''m no expert with VB but here is how it would be done in C#

for (int i =0; i< listView1.Items.Count; i++)
{
 string value = listView1.Items[i].Text;
 string Query = "INSERT INTO stockinhand(stockcode,stocknamename,quantity)VALUES ('" + value + "')";
}







or

string Query = String.Format("INSERT INTO stockinhand(stockcode,stocknamename,quantity)VALUES ('{0}')",value);


这篇关于l在运行时将数据从列表视图保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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