Dim rst As New ADODB.RecordsetPrivate Sub Command1_Click()
    rst.AddNew
    rst.Update
    rst.MoveLast
    If IsNull(rst.Fields("Name")) = True Then
        MsgBox "null"
    Else
        MsgBox "notnull"
        
    End If
End SubPrivate Sub Form_Load()
    Dim t As Variant
    rst.Fields.Append "Name", adVarChar, 30
    rst.Open
    rst.AddNew
    rst.Fields("Name") = "1"
    rst.Update
End SubMSDN明明说不指定默认值的话,新增的会是Null,但是确不行.还有,我新增的字段的默认值也不行,提示参数出错.

解决方案 »

  1.   

    ADO 2.8 API Reference  Append Method
    Appends an object to a collection. If the collection is Fields, a new Field object may be created before it is appended to the collection.Syntax
    collection.Append object
    fields.Append Name, Type, DefinedSize, Attrib, FieldValue
    Parameters
    collection 
    A collection object. 
    fields 
    A Fields collection. 
    object 
    An object variable that represents the object to be appended. 
    Name 
    A String value that contains the name of the new Field object, and must not be the same name as any other object in fields. 
    Type 
    A DataTypeEnum value, whose default value is adEmpty, that specifies the data type of the new field. The following data types are not supported by ADO, and should not be used when appending new fields to a Recordset: adIDispatch, adIUnknown, adVariant. 
    DefinedSize 
    Optional. A Long value that represents the defined size, in characters or bytes, of the new field. The default value for this parameter is derived from Type. Fields with a DefinedSize greater than 255 bytes, and treated as variable length columns. (The default DefinedSize is unspecified.) 
    Attrib 
    Optional. A FieldAttributeEnum value, whose default value is adFldDefault, that specifies attributes for the new field. If this value is not specified, the field will contain attributes derived from Type. 
    FieldValue 
    Optional. A Variant that represents the value for the new field. If not specified, then the field is appended with a null value. MSDN原文================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  2.   

    VarType 常数
    我用vbEmpty这个常数判断是可以的了.vbEmpty 0 未初始化(缺省值) ================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  3.   

    晕死.看了半天Field对象,似乎没有关于默认值的属性,那么这个Recordset的Append追加的默认值如何弄呢?With the collections, methods, and properties of a Field object, you can do the following: Return the name of a field with the Name property. 
    View or change the data in the field with the Value property. Value is the default property of the Field object. 
    Return the basic characteristics of a field with the Type, Precision, and NumericScale properties. 
    Return the declared size of a field with the DefinedSize property. 
    Return the actual size of the data in a given field with the ActualSize property. 
    Determine what types of functionality are supported for a given field with the Attributes property and Properties collection. 
    Manipulate the values of fields containing long binary or long character data with the AppendChunk and GetChunk methods. 
    If the provider supports batch updates, resolve discrepancies in field values during batch updating with the OriginalValue and UnderlyingValue properties. ================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  4.   

    有问题吧,应该这样吧:Set rst = New ADODB.Recordset
    With rst
        .Fields.Append "name", adBSTR, 10
        .CursorType = adOpenStatic
        .LockType = adLockOptimistic
        .Open
    End With
    If isnull(rst.Fields("Name")) Then
           ......
      

  5.   

    我看的是MS在线的MSDN,ADO版本为2.8.看2000年版的MSDN,参数要比2.8的少一个.我现在就是那个新增的参数的问题.看说明好像是定义默认值的.================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  6.   

    有些参数VB不适用,比如adVarChar在C++中是可以的
      

  7.   

    你看它的语法了吗?语法本身就用的VB的语法!怎么会不适合呢.还有,你说adVarChar只有C++是可以的?不是吧.================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  8.   

    在 recordset 中,字段不赋值默认为 Empty(除非指定了默认值),保存到数据库时就成为 NULL(除非数据库字段指定了默认值)
      

  9.   

    可以!你用 isempty 判断 。
    我也不知道isempty 和 isnull有什么不同!
    知道了告诉我,咋俩在一个群。
      

  10.   

    Dim rst As New ADODB.Recordset
    Private Sub Command1_Click()
        'rst.AddNew
        'rst.Update
        rst.MoveLast
        If IsEmpty(rst.Fields("Name")) = True Then
            MsgBox "null"
        Else
            MsgBox rst.Fields(0)
            
        End If
    End SubPrivate Sub Form_Load()
        Dim t As Variant
        rst.Fields.Append "Name", adVarChar, 30
        rst.Open
        rst.AddNew
        rst.Fields("Name") = "1"
        rst.Update
    End Sub
      

  11.   

    大哥们,我现在用IsNull+IsEmpty来判断已经搞定了.现在的问题是给新增的字段设定默认值的问题!!!!!!!!!!!!!!!!!!!!!!!!!!================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  12.   

    默认值是empty 好象不能改变。up