sp fr saving the data
IF EXISTS (SELECT billno,p.pid , p.pname as PRODUCT_NAME, QTY, RATE ,AMOUNT from trans t
join M_prdt P On P.pid = t.pid WHERE cid= @pcid and [Month] = @pmonth
and [year] = @pyear and p.pid=@ppid )
UPDATE trans set pid=@ppid ,qty=@pqty ,rate=@prate ,AMOUNT=@pamt ,billno=@pbillno ,frmdt=@pfrmdt ,todt=@ptodt
WHERE cid= @pcid and [Month] =@pmonth and [year] = @pyear and pid=@ppid and billno=@pbillno
Else
insert into trans(tid,cid,pid,qty,rate,AMOUNT,[month],[year],billno,frmdt,todt)
values (@pmaxid, @pcid ,@ppid,@pqty,@prate ,@pamt,@pmonth,@pyear,@pbillno,@pfrmdt,@ptodt)
" IF EXISTS(select * from trans WHERE cid= " & drpcust.SelectedValue & " )" _
& " (SELECT distinct p.pid , p.pname as PRODUCT_NAME, QTY, RATE ,AMOUNT, t.frmdt as From_DT, t.todt as To_DT from trans t " _
& " join M_prdt P On P.pid = t.pid " _
& " WHERE cid= " & drpcust.SelectedValue & " and [Month] = " & DateTimePicker1.Value.Month & " " _
& " and [year] = " & DateTimePicker1.Value.Year & ")" _
& " Else " _
& " (select DISTINCT p.pid , p.pname as PRODUCT_NAME,0 as QTY, p.PRATE as RATE, t.AMOUNT, frmdt as From_DT,todt as To_DT" _
& " from PRDT_TAKEN t " _
& " left join M_customer C On C.Cid = t.cust_id " _
& " left join M_prdt P On P.pid = t.pid left join trans a On a.pid = t.pid " _
& " where t.cust_id = " & drpcust.SelectedValue & ")"
Dim da1 As New SqlDataAdapter(cc)
Dim ds1 As New DataSet()
da1.Fill(ds1, "trans")
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
da1.Fill(table)
code fr grid binding