高手帮我看看这段代码那有错误

acxz520 2010-06-11 05:39:28

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String

Private Sub Command1_Click()
' txtnull

suo (False)
DataGrid1.Enabled = False
Command1.Enabled = False
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = False

End Sub

Private Sub Command2_Click()
Adodc1.Refresh

End Sub

Private Sub Command3_Click()
Dim cn As New ADODB.Connection

If funnull = False Then
str4 = "insert into 交易(衣服编号,衣服颜色,衣服样式,送衣时间,取衣时间,洗衣单价,洗衣方式,顾客姓名)&values( '" & Trim(Text1) & "','" & Trim(Text2) & "','" & Trim(Text3) & "','" & Trim(Text4) & "','" & Trim(Text5) & "','" & Trim(Text6) & "','" & Trim(Text7) & "','" & Trim(Text8) & "')"
cn.ConnectionString = conn
cn.Open
cn.Execute str4





Command3.Enabled = False
Command4.Enabled = False
DataGrid1.Enabled = True
Command1.Enabled = True
Command5.Enabled = True
cn.Close
Set cn = Nothing

End If
Form_Load



End Sub

Private Sub Command4_Click()
DataGrid1.Enabled = True
Command1.Enabled = True
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = True

End Sub

Private Sub Command5_Click()
End

End Sub

Private Sub DataGrid1_Click()

str2 = "select * from 交易"
On Error Resume Next

cnn.ConnectionString = conn
cnn.Open
Set rst.ActiveConnection = cnn
rst.Open str2
If Not rst.EOF Then


With Adodc1.Recordset
Text1.Text = .Fields("衣服编号")
Text2.Text = .Fields("衣服颜色")
Text3.Text = .Fields("衣服样式")
Text4.Text = .Fields("送衣时间")
Text5.Text = .Fields("取衣时间")
Text6.Text = .Fields("洗衣单价")
Text7.Text = .Fields("洗衣方式")
Text8.Text = .Fields("顾客姓名")
End With

End If
rst.Close
cnn.Close
Set rst = Nothing

Set cnn = Nothing

End Sub

Private Sub Form_Load()

suo (True)


Command3.Enabled = False
Command4.Enabled = False

str1 = "select * from 交易"

Adodc1.ConnectionString = conn
Adodc1.RecordSource = str1
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
DataGrid1.AllowAddNew = False
DataGrid1.AllowUpdate = False
'Adodc1.Refresh
DataGrid1.Refresh
End Sub


Private Sub suo(bshow As Boolean)
Text1.Locked = bshow
Text2.Locked = bshow
Text3.Locked = bshow
Text4.Locked = bshow
Text5.Locked = bshow
Text6.Locked = bshow
Text7.Locked = bshow
Text8.Locked = bshow
End Sub


Private Function funnull() As Boolean
If Trim(Text1) = "" Then
MsgBox "衣服编号不可以为空!", 64, "提示"
funnull = True
Text1.SetFocus
Exit Function
End If
If Trim(Text2) = "" Then
MsgBox "衣服颜色不可以为空!", 64, "提示"
funnull = True
Text2.SetFocus
Exit Function
End If
If Trim(Text3) = "" Then
MsgBox "衣服样式不可以为空!", 64, "提示"
funnull = True
Text3.SetFocus
Exit Function
End If
If Trim(Text4) = "" Then
MsgBox "送衣时间不可以为空!", 64, "提示"
funnull = True
Text4.SetFocus
Exit Function
End If
If Trim(Text5) = "" Then
MsgBox "取衣服时间不可以为空!", 64, "提示"
funnull = True
Text5.SetFocus
Exit Function
End If
If Trim(Text6) = "" Then
MsgBox "洗衣价格不可以为空!", 64, "提示"
Text6.SetFocus
funnull = True
Exit Function
End If
If Trim(Text7) = "" Then
MsgBox "洗衣方式不可以为空!", 64, "提示"
Text7.SetFocus
funnull = True
Exit Function
End If
If Trim(Text8) = "" Then
MsgBox "顾客姓名不可以为空!", 64, "提示"
Text8.SetFocus
funnull
Exit Function
End If

End Function


Private Sub txtnull()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text6 = ""
Text7 = ""
Text8 = ""
End Sub
...全文
36 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinaboyzyq 2010-06-11
  • 打赏
  • 举报
回复
用 Adodc1.Refresh打开数据表前要先执行数据源语句。

举例如下:
Private Sub Command2_Click()
Adodc1.RecordSource =“select * from 你的表"
Adodc1.Refresh

End Sub

acxz520 2010-06-11
  • 打赏
  • 举报
回复
为什么程序运行的时候一点COMMAND2按扭就提示FROM子句语法错误 对象refresh的方法IAdodc失败

救人啊

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧