ERROR IN SAVING STATEMENT ...

  • Thread starter Thread starter Omi4u
  • Start date Start date
O

Omi4u

Guest
Dear All

i wrote a statements to save data from vb.net to sql server but im getting error

below is my code

Try
con.ConnectionString = (appx.myconnection)
con.Open()
cmd.Connection = con
For Each rowac As DataGridViewRow In DataGridView1.Rows
If Not rowac.IsNewRow Then
cmd.CommandText = "insert into bankpayment(bankpaymentid,date,accountiddr,debitaccount,accountidcr,creditaccount,debitamount,creditamount,type,narrations,totalamountdr,totalamountcr,unit,textid) Values (@bankpaymentid,@date,@accountiddr,@debitaccount,@accountidcr,@creditaccount,@debitamount,@creditamount,@type,@narrations,@totalamountdr,@totalamountcr,@unit,@textid)"
cmd.Parameters.Add("@bankpaymentid", SqlDbType.VarChar, 50).Value = rowac.Cells(2).Value
cmd.Parameters.Add("@date", SqlDbType.Date).Value = rowac.Cells(3).Value
cmd.Parameters.Add("@accountiddr", SqlDbType.VarChar, 50).Value = rowac.Cells(4).Value
cmd.Parameters.Add("@debitaccount", SqlDbType.VarChar, 50).Value = rowac.Cells(5).Value
cmd.Parameters.Add("@accountidcr", SqlDbType.VarChar, 50).Value = SearchLookUpEdit1.Text
cmd.Parameters.Add("@creditaccount", SqlDbType.VarChar, 50).Value = CreditaccountTextEdit.Text
cmd.Parameters.Add("@debitamount", SqlDbType.Decimal).Value = rowac.Cells(7).Value
cmd.Parameters.Add("@creditamount", SqlDbType.Decimal).Value = rowac.Cells(8).Value
cmd.Parameters.Add("@type", SqlDbType.VarChar, 50).Value = TypeTextEdit.Text
cmd.Parameters.Add("@narrations", SqlDbType.VarChar, 100).Value = rowac.Cells(6).Value
cmd.Parameters.Add("@totalamountdr", SqlDbType.Decimal).Value = TotalamountdrLabel1.Text
cmd.Parameters.Add("@totalamountcr", SqlDbType.Decimal).Value = TotalamountcrLabel1.Text
cmd.Parameters.Add("@unit", SqlDbType.VarChar, 50).Value = rowac.Cells(1).Value
cmd.Parameters.Add("@textid", SqlDbType.VarChar, 50).Value = rowac.Cells(12).Value
cmd.ExecuteNonQuery()
End If
Next
Catch ex As Exception
MsgBox(ex.Message & " " & "Error Code : BPV-SV-001", vbOKOnly + vbCritical, "Error Code : BPV-SV-001")
Finally
con.Close()
End Try

'----------------------------------------------------------------------------------------------------------

Try
con.ConnectionString = (appx.myconnection)
con.Open()
cmd.Connection = con
For Each rowab As DataGridViewRow In DataGridView1.Rows
If Not rowab.IsNewRow Then
cmd.CommandText = "insert into bankpaymentjoin(serialnox,unit,bankpaymentid,date,accountiddr,debitaccount,accountidcr,creditaccount,amountdebit,amountcredit,narration,amountinwords,username) VALUES (@dserialnox,@dunit,@dbankpaymentid,@ddate,@daccountiddr,@ddebitaccount,@daccountidcr,@dcreditaccount,@damountdebit,@damountcredit,@dnarration,@damountinwords,@dusername)"
cmd.Parameters.Add("@dserialnox", SqlDbType.Int).Value = rowab.Cells(0).Value
' cmd.Parameters.AddWithValue("@dserialnox", rowa.Cells(0).Value)
cmd.Parameters.Add("@dunit", SqlDbType.VarChar, 50).Value = rowab.Cells(1).Value
cmd.Parameters.Add("@dbankpaymentid", SqlDbType.VarChar, 50).Value = rowab.Cells(2).Value
cmd.Parameters.Add("@ddate", SqlDbType.Date).Value = rowab.Cells(3).Value
cmd.Parameters.Add("@daccountiddr", SqlDbType.VarChar, 50).Value = rowab.Cells(4).Value
cmd.Parameters.Add("@ddebitaccount", SqlDbType.VarChar, 50).Value = rowab.Cells(5).Value
cmd.Parameters.Add("@daccountidcr", SqlDbType.VarChar, 50).Value = SearchLookUpEdit1.Text
cmd.Parameters.Add("@dcreditaccount", SqlDbType.VarChar, 50).Value = CreditaccountTextEdit.Text
cmd.Parameters.Add("@damountdebit", SqlDbType.Decimal).Value = rowab.Cells(7).Value
cmd.Parameters.Add("@damountcredit", SqlDbType.Decimal).Value = rowab.Cells(8).Value
cmd.Parameters.Add("@dnarration", SqlDbType.VarChar, 100).Value = rowab.Cells(6).Value
cmd.Parameters.Add("@damountinwords", SqlDbType.VarChar, 50).Value = AmountinwordsLabel1.Text
cmd.Parameters.Add("@dusername", SqlDbType.VarChar, 50).Value = UsernameTextEdit.Text
cmd.ExecuteNonQuery()
End If
Next

Catch ex As Exception
MsgBox(ex.Message & " " & "Error Code : BPV-SV-002", vbOKOnly + vbCritical, "Error Code : BPV-SV-002")
Finally
con.Close()
End Try

'----------------------------------------------------------------------------------------------------------

Try
con.ConnectionString = (appx.myconnection)
con.Open()
cmd.Connection = con
For Each rowb As DataGridViewRow In DataGridView2.Rows
If Not rowb.IsNewRow Then
cmd.CommandText = "insert into ledgerreport(dateledger,serialno,voucherid,debitamount,creditamount,description,closingbalance,unit,accountiddr,accountnamedr,accountidcr,accountnamecr) VALUES (@ldateledger,@lserialno,@lvoucherid,@LDEBITAMOUNT,@LCREDITAMOUNT,@Ldescription,@lclosingbalance,@lunit,@laccountiddr,@laccountnamedr,@laccountidcr,@laccountnamecr)"
' cmd.Parameters.AddWithValue("@lserialno", row.Cells(1).Value)
cmd.Parameters.Add("@ldateledger", SqlDbType.Date).Value = rowb.Cells(0).Value
cmd.Parameters.Add("@lserialno", SqlDbType.Int).Value = rowb.Cells(1).Value
cmd.Parameters.Add("@lvoucherid", SqlDbType.VarChar, 50).Value = rowb.Cells(6).Value
cmd.Parameters.Add("@LDEBITAMOUNT", SqlDbType.Decimal).Value = rowb.Cells(7).Value
cmd.Parameters.Add("@LCREDITAMOUNT", SqlDbType.Decimal).Value = rowb.Cells(8).Value
cmd.Parameters.Add("@Ldescription", SqlDbType.VarChar, 50).Value = rowb.Cells(9).Value
cmd.Parameters.Add("@lclosingbalance", SqlDbType.Decimal).Value = rowb.Cells(10).Value
cmd.Parameters.Add("@lunit", SqlDbType.VarChar, 50).Value = rowb.Cells(11).Value
cmd.Parameters.Add("@laccountiddr", SqlDbType.VarChar, 50).Value = rowb.Cells(2).Value
cmd.Parameters.Add("@laccountnamedr", SqlDbType.VarChar, 50).Value = rowb.Cells(3).Value
cmd.Parameters.Add("@laccountidcr", SqlDbType.VarChar, 50).Value = rowb.Cells(4).Value
cmd.Parameters.Add("@laccountnamecr", SqlDbType.VarChar, 50).Value = rowb.Cells(5).Value
cmd.ExecuteNonQuery()
End If
Next
Catch ex As Exception
MsgBox(ex.Message & " " & "Error Code : BPV-LG-001", vbOKOnly + vbCritical, "Error Code : BPV-LG-001")
Finally
con.Close()
End Try

'----------------------------------------------------------------------------------------------------------

Try
con.ConnectionString = (appx.myconnection)
con.Open()
cmd.Connection = con
For Each rowx As DataGridViewRow In DataGridView1.Rows
If Not rowx.IsNewRow Then
cmd.CommandText = "insert into accountserialnox(serialnox) VALUES (@asserialnox)"
cmd.Parameters.Add("@asserialnox", SqlDbType.Int).Value = rowx.Cells(0).Value
cmd.ExecuteNonQuery()
End If
Next
Catch ex As Exception
MsgBox(ex.Message & " " & "Error Code : BPV-SR-001", vbOKOnly + vbCritical, "Error Code : BPV-SR-001")
Finally
con.Close()
End Try


'----------------------------------------------------------------------------------------------------------

Try
For Each row As DataGridViewRow In DataGridView1.Rows
Using cn As New SqlConnection(appx.myconnection)
cn.Open()
Using com As New SqlCommand("", cn)
com.CommandText = "Update COA set openingbalance = openingbalance - @dr where coaid=@id"
com.Parameters.AddWithValue("@id", SearchLookUpEdit1.Text)
com.Parameters.AddWithValue("@dr", row.Cells(8).Value)
com.ExecuteNonQuery()
com.CommandText = "Update COA set openingbalance = openingbalance + @dr where coaid=@id"
com.Parameters("@id").Value = row.Cells(4).Value
com.Parameters("@dr").Value = row.Cells(7).Value
com.ExecuteNonQuery()
End Using
End Using
Next
Catch ex As Exception
MsgBox(ex.Message & " " & "Error Code : BPV-UP-001", vbOKOnly + vbCritical, "Error Code : BPV-UP-001")

End Try

'----------------------------------------------------------------------------------------------------------

Try
con.ConnectionString = (appx.myconnection)
con.Open()
cmd.Connection = con
For Each rowz As DataGridViewRow In DataGridView1.Rows
If Not rowz.IsNewRow Then
cmd.CommandText = "insert into ledgerbalance(coaid,accounttitle,dated,openingbalance,closingbalance) VALUES (@dcoaid,@daccounttitle,@ddated,@dopeningbalance,@dclosingbalance)"
cmd.Parameters.AddWithValue("@dcoaid", rowz.Cells(4).Value)
cmd.Parameters.AddWithValue("@daccounttitle", rowz.Cells(5).Value)
cmd.Parameters.AddWithValue("@ddated", rowz.Cells(3).Value)
cmd.Parameters.AddWithValue("@dopeningbalance", blncetxt.Text)
cmd.Parameters.AddWithValue("@dclosingbalance", TextBox7.Text)
cmd.ExecuteNonQuery()
End If
Next
Catch ex As Exception
MsgBox(ex.Message & " " & "Error Code : BPV-LBS-001", vbOKOnly + vbCritical, "Error Code : BPV-LBS-001")
Finally
con.Close()
End Try

'----------------------------------------------------------------------------------------------------------

Try
con.ConnectionString = (appx.myconnection)
con.Open()
cmd.Connection = con
For Each rowa1 As DataGridViewRow In DataGridView1.Rows
If Not rowa1.IsNewRow Then
cmd.CommandText = "insert into ledgerbalance(coaid,accounttitle,dated,openingbalance,closingbalance) VALUES (@dxcoaid,@dxaccounttitle,@dxdated,@dxopeningbalance,@dxclosingbalance)"
cmd.Parameters.AddWithValue("@dxcoaid", SearchLookUpEdit1.Text)
cmd.Parameters.AddWithValue("@dxaccounttitle", CreditaccountTextEdit.Text)
cmd.Parameters.AddWithValue("@dxdated", rowa1.Cells(3).Value)
cmd.Parameters.AddWithValue("@dxopeningbalance", blncetxtcr.Text)
cmd.Parameters.AddWithValue("@dxclosingbalance", TextBox6.Text)
cmd.ExecuteNonQuery()
End If
Next

Catch ex As Exception
MsgBox(ex.Message & " " & "Error Code : BPV-LBS-002", vbOKOnly + vbCritical, "Error Code : BPV-LBS-002")
Finally
con.Close()
End Try


errors im getting is


1553817.png

1553818.png


1553819.png

1553820.png


Please guide and help to solve these errors

Continue reading...
 
Back
Top