Private Sub cmdCheckData_Click() 'DAO²»ÊìϤ£¬¸øÄãÒ»¸öADOµÄÀý×Ó 'ÏÈÖØÖÃÎı¾¿òΪ¿Õ txtResult.Text = ""
'Á¬½ÓÊý¾Ý¿â Dim cnnOpenDatabase As ADODB.Connection Set cnnOpenDatabase = New ADODB.Connection 'Ìæ»»Êý¾Ý¿âf:\a.mdbµ½ÄãµÄAccessÎļþ cnnOpenDatabase.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\a.mdb;Persist Security Info=False"
'²éѯ±íÊÇ·ñ´æÔÚ Dim rsCheckTable As ADODB.Recordset Set rsCheckTable = New ADODB.Recordset
'¼ìË÷Êý¾Ý£¬¸ù¾ÝÄãµÄÄÚÈÝÑ¡ÔñʹÓÃcmbCheckType.Text»òÕßcmbCheckType.Index rsCheckTable.Open "SELECT SUM([Count]) AS S FROM [tb_out] WHERE [Date] = #" & dtpCheckDate.Value & "# AND [Type] = '" & cmbCheckType.Text & "'", cnnOpenDatabase If IsNull(rsCheckTable.Fields("S").Value) Then Call MsgBox("ÎÞËùÑ¡Êý¾Ý£¡", vbInformation + vbOKOnly, "Ìáʾ") Else txtResult.Text = CStr(rsCheckTable.Fields("S").Value) End If rsCheckTable.Close Set rsCheckTable = Nothing Set cnnOpenDatabase = NothingEnd Sub
3楼那个是ADO的方法 不是DAO的
Private Sub Command1_Click() Dim strDB As String Dim objDB As Database Dim rs As Recordset Dim strSql As String strDB = Ypath & "test.mdb" Set objDB = OpenDatabase(strDB)
strSql = "SELECT * From aa " Set rs = objDB.OpenRecordset(strSql) text1 = rs.Fields(1) rs.Close Set rs = Nothing objDB.Close Set objDB = NothingEnd Sub
jhone99 你都挂勋章了不介意给我写个完整的吧 感激涕零
Private Sub Command1_Click() Dim strDB As String Dim objDB As Database Dim rs As Recordset Dim strSql As String strDB = app.path & "test.mdb" Set objDB = OpenDatabase(strDB)
strSql = ="select sum([count]) as [count] from tb_out where [date]=#"& dtp1.value &"# and [type] ='"& cmb2 &"' " Set rs = objDB.OpenRecordset(strSql) text2 = rs.Fields(0) rs.Close Set rs = Nothing objDB.Close Set objDB = Nothing End Sub
jhone99 你说的太对了 不是我不想修改,是有的地方不懂的, 不知道怎么学 哎 烦啊!!
Private Sub cmd_se_Click() Dim strDB As String Dim objDB As Database Dim rs As Recordset Dim strSql As String 'strDB = App.Path & "db1.mdb" 'Set objDB = OpenDatabase(strDB) strSql = "select sum([total]) as [count] from tb_out where [shi=#" & DTP1.Value & "# and [zl] ='" & cmb2 & "' " Set rs = db.OpenRecordset(strSql) Text2 = rs.fields(0) rs.Close Set rs = Nothing objDB.Close Set objDB = Nothing End Sub运行后出现错误如下: 执行阶段错误'3126' 名称'[shi=#2009-8-17#and[zl]]'的括号无效.数据库的字段名称我改了 jhone99 帮我看一下
strsql="select sum(count) as count from tb_out where date='"& dtp1.value &"' and type ='"& cmb2.index &"'"
strsql="select sum([count]) as [count] from tb_out where [date]='"& dtp1.value &"' and [type] ='"& cmb2 &"' "
strsql="select sum([count]) as [count] from tb_out where [date]=#"& dtp1.value &"# and [type] ='"& cmb2 &"' "
你们不要都讲那个SQL语句啊
'ÏÈÖØÖÃÎı¾¿òΪ¿Õ
txtResult.Text = ""
'Á¬½ÓÊý¾Ý¿â
Dim cnnOpenDatabase As ADODB.Connection
Set cnnOpenDatabase = New ADODB.Connection
'Ìæ»»Êý¾Ý¿âf:\a.mdbµ½ÄãµÄAccessÎļþ
cnnOpenDatabase.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\a.mdb;Persist Security Info=False"
'²éѯ±íÊÇ·ñ´æÔÚ
Dim rsCheckTable As ADODB.Recordset
Set rsCheckTable = New ADODB.Recordset
'¼ìË÷Êý¾Ý£¬¸ù¾ÝÄãµÄÄÚÈÝÑ¡ÔñʹÓÃcmbCheckType.Text»òÕßcmbCheckType.Index
rsCheckTable.Open "SELECT SUM([Count]) AS S FROM [tb_out] WHERE [Date] = #" & dtpCheckDate.Value & "# AND [Type] = '" & cmbCheckType.Text & "'", cnnOpenDatabase
If IsNull(rsCheckTable.Fields("S").Value) Then
Call MsgBox("ÎÞËùÑ¡Êý¾Ý£¡", vbInformation + vbOKOnly, "Ìáʾ")
Else
txtResult.Text = CStr(rsCheckTable.Fields("S").Value)
End If
rsCheckTable.Close
Set rsCheckTable = Nothing
Set cnnOpenDatabase = NothingEnd Sub
Dim rs As Recordset
Dim strSql As String
strDB = Ypath & "test.mdb" Set objDB = OpenDatabase(strDB)
strSql = "SELECT * From aa " Set rs = objDB.OpenRecordset(strSql)
text1 = rs.Fields(1)
rs.Close
Set rs = Nothing
objDB.Close
Set objDB = NothingEnd Sub
感激涕零
Dim rs As Recordset
Dim strSql As String
strDB = app.path & "test.mdb" Set objDB = OpenDatabase(strDB)
strSql = ="select sum([count]) as [count] from tb_out where [date]=#"& dtp1.value &"# and [type] ='"& cmb2 &"' " Set rs = objDB.OpenRecordset(strSql)
text2 = rs.Fields(0)
rs.Close
Set rs = Nothing
objDB.Close
Set objDB = Nothing End Sub
不是我不想修改,是有的地方不懂的,
不知道怎么学
哎
烦啊!!
Dim strDB As String Dim objDB As Database
Dim rs As Recordset
Dim strSql As String
'strDB = App.Path & "db1.mdb" 'Set objDB = OpenDatabase(strDB)
strSql = "select sum([total]) as [count] from tb_out where [shi=#" & DTP1.Value & "# and [zl] ='" & cmb2 & "' "
Set rs = db.OpenRecordset(strSql)
Text2 = rs.fields(0)
rs.Close
Set rs = Nothing
objDB.Close
Set objDB = Nothing
End Sub运行后出现错误如下:
执行阶段错误'3126'
名称'[shi=#2009-8-17#and[zl]]'的括号无效.数据库的字段名称我改了
jhone99 帮我看一下