Click here to Skip to main content
15,746,248 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have tried using the following it saves the data but the data is not visible in database. I have attached the screenshot of the database below.
I am pasting my code below.

Kindly help me out as I am not getting what to do further.
VB
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
       Dim comd As SqlCommand = con.CreateCommand()
       If txtPONumber.Text <> " " Then
           Try
               con.ConnectionString = obj.getconnectionstring
               con.Open()
               comd.Connection = con
               comd.CommandText = "Insert into PurchaseOrder(PoNumber,PoDate,PoCompanyName,PoSiteName,PoContactNumber,ItemNumber,itemName,Quantity,Rate,TotalAmount,GrossAmount,Discount,tax,FinalAmount) values('" & txtPONumber.Text & "','" & lblDatetime.Text & "','" & cbxCompanyName.Text & "','" & txtSiteName.Text & "','" & txtContact.Text & "',@ItemNum,@ItemNam,@Qty,@Rte,@TotalAmt,'" & txtGrossAmount.Text & "','" & txtDiscount.Text & "','" & txtTax.Text & "','" & txtFinalAmount.Text & "')"

               'Adding Parameters
               comd.Parameters.Add("@ItemNum", SqlDbType.VarChar, 50)
               comd.Parameters.Add("@ItemNam", SqlDbType.VarChar, 50)
               comd.Parameters.Add("@Qty", SqlDbType.VarChar, 50)
               comd.Parameters.Add("@Rte", SqlDbType.VarChar, 50)
               comd.Parameters.Add("@TotalAmt", SqlDbType.VarChar, 50)

               comd.Prepare()
               'Data Inserted

               For Each row As DataGridViewRow In DGVPO.Rows
                   If Not row.IsNewRow Then
                       comd.Parameters("@ItemNum").Value = row.Cells(0).Value.ToString
                       comd.Parameters("@ItemNam").Value = row.Cells(1).ToString
                       comd.Parameters("@Qty").Value = row.Cells(2).ToString
                       comd.Parameters("@Rte").Value = row.Cells(3).ToString
                       comd.Parameters("@TotalAmt").Value = row.Cells(4).ToString
                   End If
               Next
               comd.ExecuteNonQuery()
               MessageBox.Show("Data Inserted")
           Catch ex As Exception
               MessageBox.Show("Error :" & ex.ToString())
           Finally
               con.Close()
           End Try
       Else
           MessageBox.Show("Enter PoNumber")
       End If

   End Sub
&&
Posted
Updated 8-Jul-12 0:40am
v3
Comments
[no name] 8-Jul-12 6:47am    
Why are you doing this? Use paramterized queries all of the time! There is no reason that you would use parameterized queries for a couple of fields and then use string concatenation for a whole bunch other stuff.
How do you know that the data is not inserted? Are you sure you are checking the correct table in the correct database? What is the result of ExecuteNonQuery?
Sergey Alexandrovich Kryukov 8-Jul-12 14:29pm    
Absolutely right.
Hey Wes, haven't you tired to struggle with such inquirers during last days? Usually, your comments to the questions are very appropriate and correct...
--SA
[no name] 8-Jul-12 15:41pm    
Yes Sergey. Most of the time I struggle with the OPs that do not supply enough information or are just plain lazy enough not to bother doing a simple google search.
Sergey Alexandrovich Kryukov 11-Jul-12 15:45pm    
Well, at least this is a good justification for being lazy enough to avoid answering such question. :-)
--SA
Sandeep Mewara 8-Jul-12 8:20am    
Well, in the same line as Wes asked, what do you see when you DEBUG in your visual studio?

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