不能从数据库里面取值,而是把变量赋给DBGRID里面!!如果能赋值 语句改怎么写

解决方案 »

  1.   

    能啊,dbgrid.fieldsp[0],text:='dd';
      

  2.   

    好像不行,只能在DBGrid上输入
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Db, DBTables, Grids, DBGrids;type
      TForm1 = class(TForm)
        DBGrid1: TDBGrid;
        DataSource1: TDataSource;
        Table1: TTable;
        ListBox1: TListBox;
        Button1: TButton;
        Button2: TButton;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    begin
    listbox1.items.add(form1.dbgrid1.fields[0].asstring);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    table1.edit;
    form1.dbgrid1.fields[0].Value:=strtoint(edit1.Text);
    end;end.百分这么好得:)
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    listbox1.items.add(form1.dbgrid1.fields[0].asstring);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    table1.edit;
    form1.dbgrid1.v.fields[0].Value:=strtoint(edit1.Text);{这句用的DataSource.dataset就是指楼主的从数据库中直接取值}
    end;end.
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    listbox1.items.add(form1.dbgrid1.fields[0].asstring);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    table1.edit;
    form1.dbgrid1.DataSource.dataset.fields[0].Value:=strtoint(edit1.Text);{);{这句用的DataSource.dataset就是指楼主的从数据库中直接取值}
    }
    end;end.
    上层的代码发错了,
      

  6.   

    TDataSet.Fields.............Lists all non-aggregate field components of the dataset.property Fields: TFields;DescriptionUse Fields to access field components. If fields are generated dynamically at runtime, the order of field components in Fields corresponds directly to the order of columns in the table or tables underlying a dataset. If a dataset uses persistent fields, then the order of field components corresponds to the ordering of fields specified in the Fields editor at design time.When ObjectView is True, the fields are stored hierarchically, meaning any child fields of an object field are referenced by the object field and don抰 appear sequentially after the object field in the TFields.Fields array. When ObjectView is False, the fields are stored sequentially, or flattened out, meaning any child fields of an object field are stored sequentially in the TFields.Fields array.Accessing fields with the Fields property is useful for applications that:Iterate over some or all fields in a dataset.
    Work with underlying tables whose internal data structure is unknown at runtime.If an application knows the data types of individual fields, then it can read or write individual field values through the Fields property. For example, the following statement assigns a field value to the Text property of an edit box:Edit1.Text := CustTable.Fields.Fields[6].AsString;Note: The preferred method for retrieving and assigning field values is to use persistent fields or the FieldByName method.The next statements assigns a value from an edit box to a field:CustTable.Edit;CustTable.Fields.Fields[6].AsString := Edit1.Text;CustTable.Post;Note: The AggFields property is a collection of all the dataset抯 aggregated fields. Thus, AggFields and Fields are mutually exclusive collections of the dataset抯 fields. These two properties contain all of the dataset抯 fields between them.
      

  7.   

    你是说给DBGRID的列附值吗?
    dbgrid1.Columns.Items[0].Title
    有问题请发信息到我的E-mail:[email protected]