Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

VS 2008 Not able to insert data into SQL Server using List view in VB 2008

$
0
0
Hi All: I am Creating a Windows application using VB.Net. In which i have written code to insert data into SQL Server using listview in VB 2008 and Showing msg as successfully inserted. But not inserting data into the database. Kindly correct my code.

Private Sub btnsaveBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveBill.Click
If cn.State = ConnectionState.Open Then
cn.Close()
End If

If cbcname.Text = Nothing Or ListView1.Items.Count = 0 Or txttotal.Text = Nothing Then
MsgBox("Cant save incomplete information", MsgBoxStyle.Critical, Me.Text)
Exit Sub
End If
Try
Dim i As Integer = 0
Dim rs1, rs2 As String

cn.Open()
rs1 = "INSERT INTO Billinfo (Cust_name, Cust_Mobile, Flddate, Sub_total, Tax_per, Tax, Total) VALUES('" & cbcname.Text & "','" & txtMobileno.Text & "','" & dpdate.Text & "','" & txtsubtot.Text & "','" & txtper.Text & "','" & txttax.Text & "','" & txttotal.Text & "')"
cmd.ExecuteNonQuery()
cn.Close()
cbcname.Text = ""
txtMobileno.Text = ""
dpdate.Text = ""
txtsubtot.Text = ""
txtper.Text = ""
txttax.Text = ""
txttotal.Text = ""
ListView1.Items.Clear()
cn.Close()

For i = 0 To ListView1.Items.Count = -1
cn.Open()
rs2 = "INSERT INTO Item_Sold (Item_name, Item_Make, Item_Srno, Unit_Price, Unit_Quantity, Itotal) VALUES('" & ListView1.Items(i).SubItems(1).Text & "','" & ListView1.Items(i).SubItems(2).Text & "','" & ListView1.Items(i).SubItems(3).Text & "','" & ListView1.Items(i).SubItems(4).Text & "','" & ListView1.Items(i).SubItems(5).Text & "','" & ListView1.Items(i).SubItems(6).Text & "')"

cn.Close()
Next
MsgBox("Saved Successfully")
BtnPrintBill.Enabled = True

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>