我是用的是ado,在不知道表的结构的情况下,我如何往表里添加一条记录,该记录主键的值为‘new’,其他的为空或者默认值,在线等待,谢谢

解决方案 »

  1.   

    query1.insert;
    Query1.FieldByName('主键名').asstring:='New'
    Query1.post;
      

  2.   

    Query1.fieldList[0].asstring:='New'
    这里认为主键是第1字段
      

  3.   

    select * from yourtablename where 1=2
    这样取得表中的字段类型
    for i:=0 to ADOQuery1.Fields.Count-1 do
     ADOQuery1.Fields[i].DisplayName
      

  4.   

    你是否发现下面两句是一样的效果:
    INSERT INTO Users
          (User_Name, Password, Name)
    VALUES ('sdf1', 'ddd', NULL)
    /////////////////////////////////////
    INSERT INTO Users
          (User_Name, Password)
    VALUES ('sdf1', 'ddd')
    /////////////////////////////////////
      

  5.   

    VAR 
        in_PriKey:string;
        in_FieldNameList:TStringList;        in_FieldNameList:=TStringList.Create();    ClothDataModule.m_Table.GetFieldNames(in_FieldNameList);
      
        in_PriKey:=in_FieldNameList.Strings[0];
        ClothDataModule.m_Table.Last;
        ClothDataModule.m_Table.Insert;
        ClothDataModule.m_Table.FieldByName(in_PriKey).AsString:='new';
        ClothDataModule.m_Table.Post;