vb 自定义ADODB.Recordset 绑定datagrid的问题
Private Sub Form_Load()dim Outrst=ADODB.Recordset
Set OutRst = New ADODB.Recordset
With OutRst
.Fields.Append "saf22a40_pcat", adVarChar, 20, adFldIsNullable
.Fields.Append "saf22a08_mcode", adVarChar, 20, adFldIsNullable
.Fields.Append "agent_name", adVarChar, 50, adFldIsNullable
.Fields.Append "saf22a03_pcode", adVarChar, 50, adFldIsNullable
.Fields.Append "saf22a35_product_name", adVarChar, 300, adFldIsNullable
.Fields.Append "saf22a05_qty", adCurrency, , adFldIsNullable
.Fields.Append "saf22a13_sold_qty", adCurrency, , adFldIsNullable
.Fields.Append "saf22a05_oldqty", adCurrency, , adFldIsNullable
.Fields.Append "saf22a13_sold_oldqty", adCurrency, , adFldIsNullable
.Fields.Append "saf22a09_oretail_one", adCurrency, , adFldIsNullable
.Fields.Append "saf22a10_ocost_one", adCurrency, , adFldIsNullable
.Fields.Append "saf22a12_sub_amt", adCurrency, , adFldIsNullable
.Fields.Append "saf22a18_punit", adVarChar, 10, adFldIsNullable
.Fields.Append "saf22a17_runit", adVarChar, 10, adFldIsNullable
.Fields.Append "punit_name", adVarChar, 10, adFldIsNullable
.Fields.Append "runit_name", adVarChar, 10, adFldIsNullable
.Fields.Append "unit_name", adVarChar, 10, adFldIsNullable
.Fields.Append "saf22a36_bcode", adVarChar, 10, adFldIsNullable
.Fields.Append "saf22a38_docno_type", adVarChar, 10, adFldIsNullable
.Fields.Append "saf22a38_docno_date", adVarChar, 10, adFldIsNullable
.Fields.Append "saf22a38_docno_orderno", adInteger, 10, adFldIsNullable
.Fields.Append "saf22a38_docno_seq", adInteger, 10, adFldIsNullable
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.Open
End With
Set Me.DataGrid1.DataSource = OutRst
-------
然后 用相应的Text 做OutRst的栏位,在画面输入 ...
With OutRst
.AddNew
OutRst.Fields("saf22a40_pcat") = Trim(Me.saf22a40_pcat)
OutRst.Fields("saf22a08_mcode") = Trim(Me.saf22a08_mcode)
OutRst.Fields("agent_name") = Trim(Me.agent_name)
OutRst.Fields("saf22a35_product_name") = Trim(Me.saf22a35_product_name)
OutRst.Fields("saf22a03_pcode") = Trim(Me.saf22a03_pcode)
OutRst.Fields("saf22a13_sold_oldqty") = killspace(Trim(Me.saf22a13_sold_oldqty))
OutRst.Fields("saf22a05_oldqty") = killspace(Trim(Me.saf22a05_oldqty))
OutRst.Fields("saf22a05_qty") = killspace(Trim(Me.saf22a05_qty))
OutRst.Fields("saf22a13_sold_qty") = killspace(Trim(Me.saf22a13_sold_qty))
OutRst.Fields("saf22a09_oretail_one") = killspace(Trim(Me.saf22a09_oretail_one))
OutRst.Fields("saf22a10_ocost_one") = killspace(Trim(Me.saf22a10_ocost_one))
OutRst.Fields("saf22a18_punit") = Me.saf22a18_punit
OutRst.Fields("saf22a17_runit") = Me.saf22a17_runit
OutRst.Fields("unit_name") = Me.unit_name
OutRst.Fields("saf22a36_bcode") = Me.saf2201_bcode
OutRst.Fields("saf22a38_docno_type") = Me.saf22a38_docno_type
OutRst.Fields("saf22a38_docno_date") = Me.saf22a38_docno_date
OutRst.Fields("saf22a38_docno_orderno") = killspace(Trim(Me.saf22a38_docno_orderno))
OutRst.Fields("saf22a38_docno_seq") = killspace(Trim(Me.saf22a38_docno_seq))
OutRst.Fields("saf22a12_sub_amt") = killspace(Trim(Me.saf22a12_sub_amt))
.Update
这里就有个问题..怎么判断Trim(Me.saf22a40_pcat) Trim(Me.saf22a08_mcode) Trim(Me.saf22a03_pcode) 相同的,只能 存入OutRst 1次 ,如果是输入多次,则对OurRst 修改其他栏位,不做Addnew ......请高手赐教呀
这个需要先判断一下数据库里面有没有这个值,然后再决定是不是增加,也就是先要读,然后决定是增加还是修改。 --------楼上朋友这是什么意思---
if Trim(Me.saf22a40_pcat)=Trim(Me.saf22a08_mcode) and Trim(Me.saf22a08_mcode)=Trim(Me.saf22a03_pcode) then
....
end if
我想要的结果 相当 于,到OutRst里去查找 是否 存在
OutRst.Fields("saf22a40_pcat") = Trim(Me.saf22a40_pcat)
OutRst.Fields("saf22a08_mcode") = Trim(Me.saf22a08_mcode)
OutRst.Fields("saf22a03_pcode") = Trim(Me.saf22a03_pcode)
如果不存在怎 OutRst.addnew,,否则 只更新OUTRST ..只是这里的OutRst 是自定义的,而不是
rst.open "select ..where a=? and b=?" 这类查询
-----关键是我输入的数据先全部存到OutRst,然后才由Outrst存入 数据库里去..... 关键是你没搞清楚顺序,先做什么,后做什么
补充:VB , 数据库(包含打印,安装,报表)