帮忙看看这个“添加”代码有什么问题Private Sub cmd_add_Click()
DataGrid1.AllowAddNew = True
Adodc1.Recordset.AddNew
Text1.Text = ""
Text2.Text = ""
cmd_save.Enabled = True
cmd_add.Enabled = False
Dim temp1
Dim sql$
temp1 = Format(Now, "yyyymmdd")
sql = "select * from order_books where dh like '%" + temp1 + "%' order by dh"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveLast
Text1.Text = Adodc1.Recordset.Fields("dh")
Text1.Text = Val(Adodc1.Recordset.Fields("dh")) + 1
Else
Text1.Text = Format(Now, "yyyymmdd")
Text1.Text = Text1.Text + "0000"
End If
Adodc1.RecordSource = "select * from order_books order by dh"
Adodc1.Refresh
End Sub
比如我添加了一条记录200611180001,按"添加"按钮后,新的记录会覆盖原来的,也就是永远只有一条记录。帮忙看看这代码有什么问题
DataGrid1.AllowAddNew = True
Adodc1.Recordset.AddNew
Text1.Text = ""
Text2.Text = ""
cmd_save.Enabled = True
cmd_add.Enabled = False
Dim temp1
Dim sql$
temp1 = Format(Now, "yyyymmdd")
sql = "select * from order_books where dh like '%" + temp1 + "%' order by dh"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveLast
Text1.Text = Adodc1.Recordset.Fields("dh")
Text1.Text = Val(Adodc1.Recordset.Fields("dh")) + 1
Else
Text1.Text = Format(Now, "yyyymmdd")
Text1.Text = Text1.Text + "0000"
End If
Adodc1.RecordSource = "select * from order_books order by dh"
Adodc1.Refresh
End Sub
比如我添加了一条记录200611180001,按"添加"按钮后,新的记录会覆盖原来的,也就是永远只有一条记录。帮忙看看这代码有什么问题
解决方案 »
- vb_日期控件及保存照片的问题!
- jmail发信
- 如何用VB实现每隔五分钟自动弹出一个窗口???
- 请高手指教TDBGRID问题 在线等、、、、
- 请问我对combo操作的这条SQL语句怎么写啊?ADO操作access数据库
- 急!!请问如何得到用shellexecute启动EXE时传递的参数???
- 做个小调查,近来看看?
- HELP!我写了程序拿到客户那,提示COMDLG32.OCX版本不对,请问我该怎办?谢谢
- VB中用WINSOCK控件怎样接收二进制数据?
- 请问如何为一个应用程序创建一个快捷方式然后放到WINDWOS\SENDTO目录下????
- inputbox如何做一个试题程序问题,请高手来指教一下!
- 如何写自杀程序?
Text1.Text = ""
Text2.Text = ""
cmd_save.Enabled = True
cmd_add.Enabled = False
Dim temp1
Dim sql$temp1 = Format(Now, "yyyymmdd")
sql = "select * from order_books where dh like '%" + temp1 + "%' order by dh"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 ThenAdodc1.Recordset.MoveLast
Text1.Text = Adodc1.Recordset.Fields("dh")
Text1.Text = Val(Adodc1.Recordset.Fields("dh")) + 1
'上面两句是不是可以写成一句就够了(重复),此处是好不要向text1.text赋值,建立一个变量A
Else
Text1.Text = Format(Now, "yyyymmdd") ‘注释同上
Text1.Text = Text1.Text + "0000"
End IfAdodc1.Recordset.AddNew ’将此句移到此处’下面在对写
text1.text=A
Adodc1.Recordset.Update '最后别忘了
Adodc1.RecordSource = "select * from order_books order by dh"
Adodc1.Refresh
但你没有将text1和数据库关联,即text1.datasource=adodc1(在设计时设)
Adodc1.RecordSource = "select * from order_books order by dh"
Adodc1.Refresh
如果在添加状态,刷新数据是不是意味着放弃添加呢(我也不确定),去掉它们试试,