如何让MSHFLEXGRID只显示新增的记录
在单头扫描(扫描抢)一个记录,将记录INSERT INTO 表中,然后在单身MshFlexgrid 依次显示刚增加的记录,如图
该如何处理?
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim rs1 As adodb.Recordset
Set rs1 = New adodb.Recordset
Dim strDst As String
If KeyAscii = 13 Then
Adodc2.ConnectionString = publicstr
Adodc2.RecordSource = "SELECT gch,gcm,tdh,bh,barcode,cc,sl,mj,ys,cl,bzl,zc from printdata where barcode='" + Left(Text1.Text, Len(Text1.Text) - 4) + " '"
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
If Not Adodc2.Recordset.EOF Then Adodc2.Recordset.MoveLast
Text2.Text = Adodc2.Recordset.Fields("gch")
Text3.Text = Adodc2.Recordset.Fields("tdh")
Text4.Text = Adodc2.Recordset.Fields("bh")
Text5.Text = Adodc2.Recordset.Fields("cc")
Text6.Text = Adodc2.Recordset.Fields("ys")
Text7.Text = Adodc2.Recordset.Fields("bzl")
Text8.Text = Adodc2.Recordset.Fields("zc")
Text11.Text = Adodc2.Recordset.Fields("sl")
Text9.Text = Date
Text10.Text = Time()
cnn.Execute ("insert into scandata(gch,tdh,bh,barcode,cc,ys,sl,bzl,zc,stationName,scanop,scandate,scantime)values('" + Text2.Text + "','" + Text3.Text + "','" + Text4.Text + "','" + Text1.Text + "','" + Text5.Text + "','" + Text6.Text + "','" + Text11.Text + "','" + Text7.Text + "','" + Text8.Text + "','" + Label3.Caption + "','" + Label4.Caption + "','" + Text9.Text + "','" + Text10.Text + "')")
rs1.Open "insert into scandata(gch,tdh,bh,barcode,cc,ys,sl,bzl,zc,stationName,scanop,scandate,scantime)values('" + Text2.Text + "','" + Text3.Text + "','" + Text4.Text + "','" + Text1.Text + "','" + Text5.Text + "','" + Text6.Text + "','" + Text11.Text + "','" + Text7.Text + "','" + Text8.Text + "','" + Label3.Caption + "','" + Label4.Caption + "','" + Text9.Text + "','" + Text10.Text + "')", cnn, adOpenKeyset, adLockPessimistic
rs1.Open "SELECT @@Identity as myid from scandata"
'MsgBox "新增的ID为:" & rs1.Fields(0).Value
Text12.Text = rs1.Fields(0).Value
Adodc3.ConnectionString = publicstr
Adodc3.RecordSource = "select * from scandata where scanid='" + Text12.Text + "'"
Adodc3.Refresh
Set MS1.DataSource = Adodc3
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.SetFocus
Adodc3.ConnectionString = publicstr
Adodc3.RecordSource = ""
Else
MsgBox "记录不正确,请检查!", , "条码扫描"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.SetFocus
End If
End If
End Sub
barcode MSHFLEXGRID --------------------编程问答-------------------- mshflexgrid.addrow
mshfelxgrid.textmatrix(mshflexgrid.rows-1,0)="数据1"
mshfelxgrid.textmatrix(mshflexgrid.rows-1,1)="数据2"
mshfelxgrid.textmatrix(mshflexgrid.rows-1,2)="数据3"
这样直接向mshflexgrid指定的单元格写入数据。 --------------------编程问答-------------------- mshflexgrid.addrow
没这写法吧 --------------------编程问答-------------------- mshflexgrid.AddItem --------------------编程问答-------------------- 既然都用additem了,为何还要麻烦一个个格子访问呢, 直接把一整行内容写成格式化字符串放在additem后面的参数里即可, 具体写法自行参考msdn --------------------编程问答-------------------- 挖坟可耻,6字符啊6字符 --------------------编程问答-------------------- 可以试试 .TopRow
或者试试 http://www.UDchn.com
换换开发思路
补充:VB , 控件