表格如下: 字段1 字段2 字段3字段4字段5 ABC D ABC D ABC D ABC AB
如上表格;
操作界面如下:看附件
我想在MSHFlexGrid1表格中只显示其中一个字段下的所有记录,比如字段4,字段1和其他的都不显示,这个好像问题不大
最让我伤脑筋的是,我想在字段4中增加一个单元格的值,比如增加一个D变成 字段1 字段2 字段3字段4字段5 ABC D ABC D ABC D ABC D <===========这个是我要的效果 AB
这个怎么处理?我知道数据库在增加记录的时候是横向写入的,我只能做到下面这个效果 字段1 字段2 字段3字段4字段5 ABC D ABC D ABC D ABC AB D
可是这个不是我要的效果啊!我的字段是随时需要增加和减少的
这个怎么整?高手指点一下!有的话给几个代码看看!!先谢了啊!
表格如下: 字段1 字段2 字段3字段4字段5 ABC D ABC D ABC D ABC AB
这个怎么处理?我知道数据库在增加记录的时候是横向写入的,我只能做到下面这个效果 字段1 字段2 字段3字段4字段5 ABC D ABC D ABC D ABC AB D
可是这个不是我要的效果啊!我的字段是随时需要增加和减少的
这个怎么整?高手指点一下!有的话给几个代码看看!!先谢了啊!
没有哪位师傅有耗电的方法吗?我自己瞎弄了一个,帮看看有什么更好的方法,我的贴出来大家看看!
Private Sub Command3_Click()'这个是添加按钮
Dim A
Dim B
If Text1.Text = "" Then MsgBox "请输入名称!", 32, "系统" Text1.SetFocus Exit Sub
End If If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select " & Combo1.Text & " from bk " rs.Open sql, cn, 3, 3
'=======================
'循环对比是否已有记录 A = Combo1.Text B = Text1.Text Do While Not rs.EOF If Text1.Text = rs.Fields(A) & "" Then A = 1 '设置一个变量标记是否从循环退出 MsgBox "已有记录!", , "系统提示" Exit Do End If rs.MoveNext Loop If A = 1 Then'如果循环退出的 GoTo XXX'结束 End If
'=======================
rs.MoveFirst
'循环到空值将空值改为添加的值 Do While Not rs.EOF If rs.Fields(A) & "" = "" Then rs.Fields(A) = B rs.Update A = 1 Exit Do End If rs.MoveNext Loop If A = 1 Then'如果存循环退出的 GoTo XXX'结束 End If '=============================== rs.MoveFirst '再次循环,如果还没有记录就说明上面没有空值可以改变,那么直接新建 Do While Not rs.EOF If Text1.Text = rs.Fields(A) & "" Then A = 1 '设置一个变量标记是否从循环退出 MsgBox "已有记录!", , "系统提示" Exit Do End If rs.MoveNext If rs.EOF Then rs.AddNew rs.Fields(A) = B rs.Update A = 1 MsgBox "添加成功!", , "系统提示" Exit Do End If Loop If A = 1 Then'如果存循环退出的 GoTo XXX'结束 End If '===============================
XXX: If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select " & Combo1.Text & " from bk " rs.Open sql, cn, 3, 3 If rs.RecordCount > 0 Then Set MSHFlexGrid1.DataSource = rs End If
Text1.Text = ""
Text1.SetFocus
----------------------------------------------------------------------
End SubPrivate Sub Command4_Click()’这个是删除
If Text1.Text = "" Then MsgBox "无此记录!", , "系统提示" Text1.SetFocus Exit Sub
End If
If Text1.Text <> "" Then If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select " & Combo1.Text & " from bk " rs.Open sql, cn, 3, 3 '============================= A = Combo1.Text B = Text1.Text Do While Not rs.EOF If Text1.Text = rs.Fields(A) & "" Then myval = MsgBox("确定删除此记录吗?", vbYesNo, "系统") If myval = vbYes Then rs.Fields(A) = ""'不直接删除,只是把值变为空,删除的话,一行中的所有记录就会全部删除,因为我只操作单个单元格。 rs.Update End If A = 1 '设置一个变量标记是否从循环退出 MsgBox "删除成功!", , "系统提示" Exit Do End If rs.MoveNext If rs.EOF Then A = 1 MsgBox "没有这条记录!", , "系统提示" Exit Do End If Loop If A = 1 Then'如果存循环退出的 GoTo XXX'结束 End If '=============================
XXX: If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select " & Combo1.Text & " from bk " rs.Open sql, cn, 3, 3 If rs.RecordCount > 0 Then Set MSHFlexGrid1.DataSource = rs End If Text1.Text = "" Text1.SetFocus
End If
End Sub
------------------------------------------
’今天发现个以前没有找到的答案,自己想到了
'循环查询记录集一列中的所有记录加载到combo1中 If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select 区域 from qy " rs.Open sql, cn, adOpenForwardOnly, adLockBatchOptimistic Do While Not rs.EOF If rs.Fields(Combo1.Text) <> "" Then'刚想到的!刚才在数据库中把值变成空值的时候想到的,以前加载的时候连空格都加载了, '难看死了,现在加了个判断的空值就不加载了。 Combo1.AddItem rs.Fields("区域") & "" endif rs.MoveNext Loop
有好的建议请告诉我以啊!谢谢了
没有哪位师傅有耗电的方法吗?我自己瞎弄了一个,帮看看有什么更好的方法,我的贴出来大家看看!
Private Sub Command3_Click()'这个是添加按钮
Dim A
Dim B
If Text1.Text = "" Then MsgBox "请输入名称!", 32, "系统" Text1.SetFocus Exit Sub
End If If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select " & Combo1.Text & " from bk " rs.Open sql, cn, 3, 3
'=======================
'循环对比是否已有记录 A = Combo1.Text B = Text1.Text Do While Not rs.EOF If Text1.Text = rs.Fields(A) & "" Then A = 1 '设置一个变量标记是否从循环退出 MsgBox "已有记录!", , "系统提示" Exit Do End If rs.MoveNext Loop If A = 1 Then'如果循环退出的 GoTo XXX'结束 End If
'=======================
rs.MoveFirst
'循环到空值将空值改为添加的值 Do While Not rs.EOF If rs.Fields(A) & "" = "" Then rs.Fields(A) = B rs.Update A = 1 Exit Do End If rs.MoveNext Loop If A = 1 Then'如果存循环退出的 GoTo XXX'结束 End If '=============================== rs.MoveFirst '再次循环,如果还没有记录就说明上面没有空值可以改变,那么直接新建 Do While Not rs.EOF If Text1.Text = rs.Fields(A) & "" Then A = 1 '设置一个变量标记是否从循环退出 MsgBox "已有记录!", , "系统提示" Exit Do End If rs.MoveNext If rs.EOF Then rs.AddNew rs.Fields(A) = B rs.Update A = 1 MsgBox "添加成功!", , "系统提示" Exit Do End If Loop If A = 1 Then'如果存循环退出的 GoTo XXX'结束 End If '===============================
XXX: If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select " & Combo1.Text & " from bk " rs.Open sql, cn, 3, 3 If rs.RecordCount > 0 Then Set MSHFlexGrid1.DataSource = rs End If
Text1.Text = ""
Text1.SetFocus
----------------------------------------------------------------------
End SubPrivate Sub Command4_Click()’这个是删除
If Text1.Text = "" Then MsgBox "无此记录!", , "系统提示" Text1.SetFocus Exit Sub
End If
If Text1.Text <> "" Then If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select " & Combo1.Text & " from bk " rs.Open sql, cn, 3, 3 '============================= A = Combo1.Text B = Text1.Text Do While Not rs.EOF If Text1.Text = rs.Fields(A) & "" Then myval = MsgBox("确定删除此记录吗?", vbYesNo, "系统") If myval = vbYes Then rs.Fields(A) = ""'不直接删除,只是把值变为空,删除的话,一行中的所有记录就会全部删除,因为我只操作单个单元格。 rs.Update End If A = 1 '设置一个变量标记是否从循环退出 MsgBox "删除成功!", , "系统提示" Exit Do End If rs.MoveNext If rs.EOF Then A = 1 MsgBox "没有这条记录!", , "系统提示" Exit Do End If Loop If A = 1 Then'如果存循环退出的 GoTo XXX'结束 End If '=============================
XXX: If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select " & Combo1.Text & " from bk " rs.Open sql, cn, 3, 3 If rs.RecordCount > 0 Then Set MSHFlexGrid1.DataSource = rs End If Text1.Text = "" Text1.SetFocus
End If
End Sub
------------------------------------------
’今天发现个以前没有找到的答案,自己想到了
'循环查询记录集一列中的所有记录加载到combo1中 If cn.State = adStateOpen Then cn.Close If rs.State = adStateOpen Then rs.Close cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\fyxx.mdb;Jet OLEDB:Database Password=88 " sql = "select 区域 from qy " rs.Open sql, cn, adOpenForwardOnly, adLockBatchOptimistic Do While Not rs.EOF If rs.Fields(Combo1.Text) <> "" Then'刚想到的!刚才在数据库中把值变成空值的时候想到的,以前加载的时候连空格都加载了, '难看死了,现在加了个判断的空值就不加载了。 Combo1.AddItem rs.Fields("区域") & "" endif rs.MoveNext Loop
有好的建议请告诉我以啊!谢谢了