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
11 6113
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
Your list count will return “1 to count” and your index value will go in “0 to count-1”
did you tried like - Do Until iLoop = iCount -1
Hi,
You are getting the exception 'Out of Range Argument' exception because value of iCount is getting above the total no of ListView items present.
You can do it both the ways
1) Do until iloop= icount -1
2) If you do it using the following way :
foreach(ListItem l in ListView1.Items)
{
query3.CommandText = "insert into inv_dtl(invid,matgroup)values " _
& "(" & Me.TextBox1.Text & ",'" _
& "'" & l.SubItems(0).ToString & "')"
}
You do not have to keep count of iCount variable.
Your list count will return “1 to count” and your index value will go in “0 to count-1”
did you tried like - Do Until iLoop = iCount -1
ive tried this one. i havent receive any error but the data in my listview didnt save in sql.
Hi,
You are getting the exception 'Out of Range Argument' exception because value of iCount is getting above the total no of ListView items present.
You can do it both the ways
1) Do until iloop= icount -1
2) If you do it using the following way :
foreach(ListItem l in ListView1.Items)
{
query3.CommandText = "insert into inv_dtl(invid,matgroup)values " _
& "(" & Me.TextBox1.Text & ",'" _
& "'" & l.SubItems(0).ToString & "')"
}
You do not have to keep count of iCount variable.
im trying to use the 2nd one. is this for a vb.net? the item in the for each listitem and I are variable?
Hi,
That code provided is C#, vb .net code is not a C type code
Following is the (hopefully) convert version of the C# code to VB .Net using an online coverter. Hope this will explain what the code meant. - foreach(ListItem l in ListView1.Items)
-
{
-
query3.CommandText = "insert into inv_dtl(invid,matgroup)values " _
-
& "(" & Me.TextBox1.Text & ",'" _
-
& "'" & l.SubItems(0).ToString & "')"
-
}
Hi,
That code provided is C#, vb .net code is not a C type code
Following is the (hopefully) convert version of the C# code to VB .Net using an online coverter. Hope this will explain what the code meant. - foreach(ListItem l in ListView1.Items)
-
{
-
query3.CommandText = "insert into inv_dtl(invid,matgroup)values " _
-
& "(" & Me.TextBox1.Text & ",'" _
-
& "'" & l.SubItems(0).ToString & "')"
-
}
are this variables? do i have to decalre them? sori for my ignorance.
by the way back to my code. after debugging it its quite unusual eventhough ive added items to my listview still the icount returns 0 value. even if i set a value to icount it still returns 0. i think this were the problem is. your help is greatly appreciated. TIA
iCount = ListView1.Items.Count.ToString
If iCount > 0 Then
Do Until iLoop = iCount - 1
query3.CommandText = "insert into inv_dtl(invid,matgroup,material_code,material,qty, uom,price,gross,vat,net)values " _
& "(" & Me.TextBox1.Text & ",'" _
& "'" & ListView1.Items.Item(iCount).SubItems(2).ToString & "')"
query3.ExecuteNonQuery()
iLoop = iLoop + 1
Loop
End If
guys i already did it! yahoo! by the way heres the code for reference. thanks to all of you.
If Not ListView1.Items.Count = 0 Then
Do Until iLoop = ListView1.Items.Count
LvItem = ListView1.Items.Item(iLoop)
With LvItem
query3.CommandText = "insert into inv_dtl(invid,matgroup,material_code,material,qty, uom,price,gross,vat,net) values " _
& "('" & TextBox1.Text & "','" & .SubItems(0).Text & "','" & .SubItems(1).Text & "','" & .SubItems(2).Text & "','" & .SubItems(3).Text & "','" & .SubItems(4).Text & "','" & .SubItems(5).Text & "','" & .SubItems(6).Text & "','" & .SubItems(7).Text & "','" & .SubItems(8).Text & "')"
query3.ExecuteNonQuery()
End With
iLoop = iLoop + 1
LvItem = Nothing
Loop
End If
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rico Alexander |
last post by:
is there a way to retrieve the value of an autoincrement column inserted in
the database?
|
by: Fahad |
last post by:
I have a web forms that I insert data in database using
arabic and Farsi language. The problem is when I insert a
record, A record is added but I get blank fields in the
columns. When I insert a...
|
by: Joe |
last post by:
Anyone can suggest the best method of reading XML and adding data to
ListView?
Here is the xml data structure::
<xml>
<site>
<url>http://www.yahoo.com</url>
<lastupdate></lastupdate>...
|
by: Jaraba |
last post by:
In Microsoft SQL I can run the following command:
insert into table execute proc1
to insert data into a table.
Is there a comparable way to do this in DB2?
|
by: pd123 |
last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error "
The name 'Peter' is...
|
by: le0 |
last post by:
Guys,
I create a simple insertion in a database using DetailsView control, when i
run this page and try to insert some data, the browser returns an error like
this
...
|
by: boss1 |
last post by:
Hi all,
i m having a problem with inserting data in oracle db.
When i use form action =(call self page) then data is inserting properly.But problem with when using form...
|
by: AlexanderDeLarge |
last post by:
Hi!
I got a problem that's driving me crazy and I'm desperately in need of help.
I'll explain my scenario:
I'm doing a database driven site for a band, I got these tables for their discography...
|
by: Andre Saputra |
last post by:
Dear all.
I really need help for my code.
im using text box to filter data in listview, heres the code
reloadlistview1 "select * from sales where TANGGAL between #" & Text1.Text & "#" & _
...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |