使用Listview在SQL中插入DATA [英] Inserting DATA in SQL using Listview

查看:80
本文介绍了使用Listview在SQL中插入DATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,美好的一天!我使用listview时遇到问题。你能帮忙解决这个问题吗?我不知道如何编码。在填充listview之后,我希望它将集合中的所有数据保存到sql中的表。


TIA

解决方案




你可以试试这个:


foreach(ListBox1.Items中的ListItem l)

{

if(l.Selected)

{

//插入数据

}

}


伙计们好日子!我使用listview时遇到问题。你能帮忙解决这个问题吗?我不知道如何编码。在填充listview之后,我希望它将集合中的所有数据保存到sql中的表。


TIA


< blockquote> sory为我的无知。我是一个noobie。你可以解释一下吗?


顺便提一下我的代码。


Dim iCount As Integer

昏暗的iLoop作为整数

query3 =新的SqlCommand

query3.Connection = connection

iCount = ListView1.Items.Count

如果不是iCount = 0则

Do iLoop = iCount

query3.CommandText =" insert into inv_dtl(invid,matgroup)values" _

& "(&&;& Me.TextBox1.Text&",''" _

&"''"& ListView1.Items.Item(iCount).SubItems (0).ToString&"'')"


query3.ExecuteNonQuery()

iLoop = iLoop + 1


循环

结束如果


我总是收到错误

"指定的参数不在有效值的范围。参数名称:''1''不是''displayindex'的有效值。


我注意到这个数字取决于我在我的行数列表显示。我迫切需要你的帮助。


TIA


guys good day! i have a problem using listview. can you help with the syntax? i have no idea how to code this. after populating the listview i want it to save all data from the collection to the table in sql.

TIA

解决方案

Hi,

You can try this :

foreach(ListItem l in ListBox1.Items)
{
if(l.Selected)
{
//insert data
}
}


guys good day! i have a problem using listview. can you help with the syntax? i have no idea how to code this. after populating the listview i want it to save all data from the collection to the table in sql.

TIA


sory for my ignorance. im a noobie. can u expound it a little more?


by the way heres my code.

Dim iCount As Integer
Dim iLoop As Integer
query3 = New SqlCommand
query3.Connection = connection
iCount = ListView1.Items.Count
If Not iCount = 0 Then
Do Until iLoop = iCount

query3.CommandText = "insert into inv_dtl(invid,matgroup)values " _
& "(" & Me.TextBox1.Text & ",''" _
& "''" & ListView1.Items.Item(iCount).SubItems(0).ToString & "'')"

query3.ExecuteNonQuery()
iLoop = iLoop + 1

Loop
End If

I always get the error
"Specified argument was out of the range of valid values.Parameter name: ''1''is not a valid value for ''displayindex''

Ive notice that the number depends on how many rows i have in my listview. I desperately need your help guys.

TIA


这篇关于使用Listview在SQL中插入DATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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