查询的时候进行设置(如果为0则置空):类似: select case when col1='0' then null else col1 end as col1 ,case when col2='0' then null else col2 end as col2 from tbName
查询的时候进行设置(如果为0则置空):类似: select case when col1='0' then null else col1 end as col1 ,case when col2='0' then null else col2 end as col2 from tbName ------------------------- 您的方法可以,不过我觉得这样做代码量太大了,凡是数字型数据都要转换一下. 我还是想从显示控件上想办法.
引用:Microsoft Data Formatting Object Library 6.0 Dim WithEvents osDFSum As StdDataFormat Private Sub oSDFSum_Format(ByVal DataValue As StdFormat.StdDataValue) 自己寫語句 End Sub
难道datagrid的功有这么弱吗?
Option Explicit Dim Cn As New ADODB.Connection Dim WithEvents osDGFormat As StdDataFormatPrivate Sub Command1_Click() Dim Rst As New ADODB.Recordset Dim Sql As String Sql = "select no,name,num from tablename Rst.CursorLocation = adUseClient Rst.Open Sql, Cn, adOpenStatic, adLockPessimistic
Set DataGrid.DataSource = Rst
Set DataGrid.Columns(2).DataFormat = osDGFormat End SubPrivate Sub Form_Load() Cn.ConnectionString = "Driver=SQL Server;Server=192.168.2.1;uid=sa;pwd=123456;database=TEST" Cn.Open Set osDGFormat = New StdDataFormat End SubPrivate Sub osDGFormat_Format(ByVal DataValue As StdFormat.StdDataValue) DataValue.Value = FormatDataGrid(DataValue.Value) End SubPublic Function FormatDataGrid(Txt As Variant) As String On Error Resume Next If IsNull(Txt) Then FormatDataGrid = "" ElseIf Txt = 0 Then FormatDataGrid = "" Else FormatDataGrid = Txt End If End Function 用以上的方法試試 記得引用:Microsoft Data Formatting Object Library 6.0
select case when col1='0' then null else col1 end as col1 ,case when col2='0' then null else col2 end as col2 from tbName =============================== 这个方法很好了 是实现功能的最简单途径了阿
如果是数据库查询出来,通过ado控件绑定
我想也只有row ,col循环判断了!
如果是数据库查询出来,通过ado控件绑定
我想也只有row ,col循环判断了!
-----------
谢谢,不过我问的是datagrid,不是flexgrid,好象以前听说有哪个属性可以设置datagrid可以不显示0的.即数值为0时不显示.这样显得清爽些.
select case when col1='0' then null else col1 end as col1 ,case when col2='0' then null else col2 end as col2 from tbName
select case when col1='0' then null else col1 end as col1 ,case when col2='0' then null else col2 end as col2 from tbName
-------------------------
您的方法可以,不过我觉得这样做代码量太大了,凡是数字型数据都要转换一下.
我还是想从显示控件上想办法.
Dim WithEvents osDFSum As StdDataFormat
Private Sub oSDFSum_Format(ByVal DataValue As StdFormat.StdDataValue)
自己寫語句
End Sub
Dim Cn As New ADODB.Connection
Dim WithEvents osDGFormat As StdDataFormatPrivate Sub Command1_Click()
Dim Rst As New ADODB.Recordset
Dim Sql As String
Sql = "select no,name,num from tablename
Rst.CursorLocation = adUseClient
Rst.Open Sql, Cn, adOpenStatic, adLockPessimistic
Set DataGrid.DataSource = Rst
Set DataGrid.Columns(2).DataFormat = osDGFormat
End SubPrivate Sub Form_Load()
Cn.ConnectionString = "Driver=SQL Server;Server=192.168.2.1;uid=sa;pwd=123456;database=TEST"
Cn.Open
Set osDGFormat = New StdDataFormat
End SubPrivate Sub osDGFormat_Format(ByVal DataValue As StdFormat.StdDataValue)
DataValue.Value = FormatDataGrid(DataValue.Value)
End SubPublic Function FormatDataGrid(Txt As Variant) As String
On Error Resume Next
If IsNull(Txt) Then
FormatDataGrid = ""
ElseIf Txt = 0 Then
FormatDataGrid = ""
Else
FormatDataGrid = Txt
End If
End Function
用以上的方法試試
記得引用:Microsoft Data Formatting Object Library 6.0
===============================
这个方法很好了
是实现功能的最简单途径了阿