如何使用修剪将数据从ListView保存到SQL数据库 [英] How to save data from ListView to SQL Database Using Trim

查看:87
本文介绍了如何使用修剪将数据从ListView保存到SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在使用以下代码将数据从列表视图插入到sql表中

i'm using the below code to insert data from listview to sql table

 

但是问题是我不会重复数据,我会尝试使用trim但不能正常工作

but the problem is that i won't data duplicate i try to use trim but not works

只有在新数据存在的情况下,有人才能帮忙插入新数据

can some one help to insert new data only if it's exist

确定是否不会添加任何东西

and sure if not will add nothing

 

谢谢

我希望有人能在大多数时间提供帮助,我不知道为什么没有答案

and i wish some one can help most of time no one reply here i dunno why

 

推荐答案

抱歉,我忘记了代码

i forget the code sorry

 


       Dim iCount As Integer
      Dim iLoop As Integer
      Dim query3 As New SqlCommand
      Dim lvitem
      query3.Connection = New SqlConnection("Password=sasa;Persist Security Info=True;User ID=sa;Initial Catalog=Tel;Data Source=HA-PC")
      query3.Connection.Open()

        iCount = lvLogs.Items.Count
     For iLoop = 0 To lvLogs.Items.Count - 1
        If Not lvLogs.Items.Count = 0 Then
    'Do Until iLoop = lvLogs.Items.Count

        lvitem = lvLogs.Items.Item(iLoop)

       With lvitem

       query3.CommandText = "insert into A(a,b,c,d,e) values " _
      & "('" & lvitem.subitems(0).text & "','" & lvitem.subitems(1).text & "','" & lvitem.subitems(2).Text & "','" & lvitem.subitems(3).Text & "','" & lvitem.subitems(4).Text & "')"
      '" & .SubItems(6).Text & "','" & .SubItems(7).Text & "','" & .SubItems(8).Text & "')"
     query3.ExecuteNonQuery()
     End With

        iLoop = iLoop + 1
        lvitem = Nothing
      Loop
    MsgBox("done")
     End If


这篇关于如何使用修剪将数据从ListView保存到SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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