以下是我更新发票中的项目的代码。 我添加了一些项目并根据值更新了一些项目,但它只是向所有行插入或更新相同的值。我认为参与者正在制造问题,请指导我纠正错误。
con.Open()
tra = con.BeginTransaction
sqlstr = "UPDATE transaction_Mas_Tab set billdate=@billdate,invoiceno=@invoiceno,TotalBillamt=@TotalBillamt,narration=@narration,orderdate=@orderdate,usercode=@usercode,lcode=@lcode,remarks=@remarks,grossamt=@grossamt where txid=@txid "
cmd = New OleDbCommand(sqlstr, con, tra)
cmd.Parameters.AddWithValue("@billdate", dtpbilldate.Text)
cmd.Parameters.AddWithValue("@invoiceno", txtinvoiceno.Text)
cmd.Parameters.AddWithValue("@TotalBillamt", Val(txtgt.Text))
cmd.Parameters.AddWithValue("@narration", txtnote.Text)
cmd.Parameters.AddWithValue("@orderdate", dtpbilldate.Text)
cmd.Parameters.AddWithValue("@usercode", usercode)
cmd.Parameters.AddWithValue("@lcode", cmbparty.SelectedValue)
cmd.Parameters.AddWithValue("@remarks", txtrmrks.Text)
cmd.Parameters.AddWithValue("@grossamt", Val(txttotalamt.Text))
cmd.Parameters.AddWithValue("@txid", txid)
cmd.ExecuteNonQuery()
For c As Integer = 0 To dgvsitemlist.Rows.Count - 1
If dgvsitemlist.Rows(c).Cells("onew").Value.ToString = "N" And dgvsitemlist.Rows(c).Cells("isdel").Value.ToString = "N" Then
sqlstr = "insert into transaction_details (txid,itemid,unit,irate,iqty,isdeleted) values(@txid,@itemid,@unit,@irate,@iqty,@isdeleted)"
cmd = New OleDbCommand(sqlstr, con, tra)
cmd.Parameters.AddWithValue("@txid", txxid)
cmd.Parameters.AddWithValue("@itemid", dgvsitemlist.Rows(c).Cells("itemid").Value.ToString)
cmd.Parameters.AddWithValue("@unit", dgvsitemlist.Rows(c).Cells("unitid").Value.ToString)
cmd.Parameters.AddWithValue("@irate", Val(dgvsitemlist.Rows(c).Cells("prate").Value))
cmd.Parameters.AddWithValue("@iqty", Val(dgvsitemlist.Rows(c).Cells("qty").Value))
cmd.Parameters.AddWithValue("@isdeleted", "N")
cmd.ExecuteNonQuery()
sqlstr = "INSERT INTO IMasterDetails ( icode,batch,prate,srate,opstock,clstock,pscheme,sscheme,itemid) values ( @icode ,@batch , @prate , @srate,@opstock,@clstock,@pscheme,@sscheme,@itemid )"
cmd = New OleDbCommand(sqlstr, con, tra)
cmd.Parameters.AddWithValue("@icode", dgvsitemlist.Rows(c).Cells("icode").Value.ToString)
cmd.Parameters.AddWithValue("@batch", dgvsitemlist.Rows(c).Cells("batch").Value.ToString)
cmd.Parameters.AddWithValue("@prate", Val(dgvsitemlist.Rows(c).Cells("prate").Value))
cmd.Parameters.AddWithValue("@srate", Val(dgvsitemlist.Rows(c).Cells("srate").Value))
cmd.Parameters.AddWithValue("@opstock", Val(dgvsitemlist.Rows(c).Cells("qty").Value))
cmd.Parameters.AddWithValue("@clstock", Val(dgvsitemlist.Rows(c).Cells("qty").Value))
cmd.Parameters.AddWithValue("@pscheme", dgvsitemlist.Rows(c).Cells("pscheme").Value.ToString)
cmd.Parameters.AddWithValue("@sscheme", dgvsitemlist.Rows(c).Cells("sscheme").Value.ToString)
cmd.Parameters.AddWithValue("@itemid", dgvsitemlist.Rows(c).Cells("itemid").Value.ToString)
ElseIf dgvsitemlist.Rows(c).Cells("onew").Value.ToString = "O" And dgvsitemlist.Rows(c).Cells("isdel").Value.ToString = "N" Then
sqlstr = "update transaction_details set itemid=@itemid,unit=@unit,irate=@irate,iqty=@iqty,isdeleted=@isdeleted where txid=@txid"
cmd = New OleDbCommand(sqlstr, con, tra)
cmd.Parameters.AddWithValue("@itemid", dgvsitemlist.Rows(c).Cells("itemid").Value.ToString)
cmd.Parameters.AddWithValue("@unit", dgvsitemlist.Rows(c).Cells("unitid").Value.ToString)
cmd.Parameters.AddWithValue("@irate", Val(dgvsitemlist.Rows(c).Cells("prate").Value))
cmd.Parameters.AddWithValue("@iqty", Val(dgvsitemlist.Rows(c).Cells("qty").Value))
cmd.Parameters.AddWithValue("@isdeleted", "N")
cmd.Parameters.AddWithValue("@txid", txxid)
cmd.ExecuteNonQuery()
sqlstr = "Update IMasterDetails set icode=@icode,batch=@batch,prate=@prate,srate=@srate,opstock=@opstock,clstock=@clstock,pscheme=@pscheme,sscheme=@sscheme where itemid=@itemid "
cmd = New OleDbCommand(sqlstr, con, tra)
cmd.Parameters.AddWithValue("@icode", dgvsitemlist.Rows(c).Cells("icode").Value.ToString)
cmd.Parameters.AddWithValue("@batch", dgvsitemlist.Rows(c).Cells("batch").Value.ToString)
cmd.Parameters.AddWithValue("@prate", Val(dgvsitemlist.Rows(c).Cells("prate").Value))
cmd.Parameters.AddWithValue("@srate", Val(dgvsitemlist.Rows(c).Cells("srate").Value))
cmd.Parameters.AddWithValue("@opstock", Val(dgvsitemlist.Rows(c).Cells("qty").Value))
cmd.Parameters.AddWithValue("@clstock", Val(dgvsitemlist.Rows(c).Cells("qty").Value))
cmd.Parameters.AddWithValue("@pscheme", dgvsitemlist.Rows(c).Cells("pscheme").Value.ToString)
cmd.Parameters.AddWithValue("@sscheme", dgvsitemlist.Rows(c).Cells("sscheme").Value.ToString)
cmd.Parameters.AddWithValue("@itemid", dgvsitemlist.Rows(c).Cells("itemid").Value.ToString)
cmd.ExecuteNonQuery()
ElseIf dgvsitemlist.Rows(c).Cells("onew").Value.ToString = "O" And dgvsitemlist.Rows(c).Cells("isdel").Value.ToString = "Y" Then
sqlstr = "update transaction_details set itemid=@itemid,unit=@unit,irate=@irate,iqty=@iqty,isdeleted=@isdeleted where txid=@txid"
cmd = New OleDbCommand(sqlstr, con, tra)
cmd.Parameters.AddWithValue("@itemid", dgvsitemlist.Rows(c).Cells("itemid").Value.ToString)
cmd.Parameters.AddWithValue("@unit", dgvsitemlist.Rows(c).Cells("unitid").Value.ToString)
cmd.Parameters.AddWithValue("@irate", Val(dgvsitemlist.Rows(c).Cells("prate").Value))
cmd.Parameters.AddWithValue("@iqty", Val(dgvsitemlist.Rows(c).Cells("qty").Value))
cmd.Parameters.AddWithValue("@isdeleted", "Y")
cmd.Parameters.AddWithValue("@txid", txxid)
cmd.ExecuteNonQuery()
End If
Next
tra.Commit()
updatebilldata = txid
clearall()
clearsave()
Catch ex As Exception
MsgBox("Some thing Went Wrong")
tra.Rollback()
updatebilldata = Nothing
End Try
End Using