Click here to Skip to main content
15,905,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Ankit Rajput 2-May-11 5:32am    
Please right down your problem here. Or provide the code which is not working.
anand4886 2-May-11 5:49am    
sir if one of variable is string then how can i write query pls tell me?
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 string
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
anand4886 2-May-11 6:15am    
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 string
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
Sandeep Mewara 2-May-11 5:32am    
Before asking for code, share the effort you have made till now.
anand4886 2-May-11 5:50am    
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

Hi,

VB
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


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

Regards
AR
 
Share this answer
 
v2
I'm no expert with VB but here is how it would be done in C#

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

C#
string Query = String.Format("INSERT INTO stockinhand(stockcode,stocknamename,quantity)VALUES ('{0}')",value);
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900