case不同的index,调用不同的sql,insert到不同的字段
解决方案 »
- 打开我的管理软件,过段时间进入屏保,再打开电脑偶尔出现以下错误: 请高手指点.
- 求助..信号! 关于过程循环的问题 70 分相送 通宵等答..
- 坐标求法
- 将数据导入到word中去,用OLE自动化好还是用COM好?
- 请教个很简单的问题delph中如何注册TServerSocket和TClientSocket
- 怎样让别人编绎不了自己的源代码?
- 16进制 高位在后 是什么意思?
- 怎样选定DBMEMO里的部分文本,并将字体和颜色进行改变?
- 怎么Delphi中的文本控件竟然没有自动折行功能,太差了吧!
- 程序删除问题
- 有在用PAXCOMPILER的朋友吗?请教个问题!
- Delphi XE7开发的ANDROID程序包含广告,怎么去除???
定义一个StringList,存储ComboBox相应的字段名;
在combobox选择事件里直接:
sql.Add('insert into 表名(' + StringList[combobox.selectedIndex] + ') values(‘ +combobox.text + ’)');
大概这个意思,属性名称可能不准确;
建议插入一条记录,UpData字段值。
通常的办法,每个字段对应一个DBCombobox(或combobox) 。
比如:Edit1对应语文,Edit2对应数学,Edit3对应物理1、读取记录行的ID
2:SQ语句
SQL:='Update 成绩单 set ';
SQl:=SQL+'语文='+#39+Trim(Edit1.Text)+#39+',';
SQl:=SQL+'数学='+#39+Trim(Edit2.Text)+#39+',';
SQl:=SQL+'物理='+#39+Trim(Edit3.Text)+#39+',';
SQl:=SQL+' where ID='+#39+ID+#39;
3、通过ADO控件执行SQL语句即可
2、TDBGrid如何打开的。知情才能参谋!
性别:s_sexDBGRID是通过绑定datasourse来实现的数据显示的!~
但是DBGRID里面的得分字段只有一个,这个是动态来显示的,就是combobox里面来确定是哪一个字段。就是这一环不知道怎搞了
项目和执行的sql这样写在数据库和存储过程中,这要可以动态的不改变程序就行执行
先试试你说的这个方法,谢谢!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, Grids, DBGrids, ADODB;type
TForm1 = class(TForm)
ComboBox1: TComboBox;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
procedure ComboBox1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function IntToBin(Value: LongInt;Size: Integer): String;
procedure SetDBGridShowColus(ch:Byte);
public
{ Public declarations }
end;var
Form1: TForm1;implementationvar
SelField:string;{$R *.dfm}procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case ComboBox1.ItemIndex of
0:begin SetDBGridShowColus(1);SelField:='A_score' end; //下面和0一样就不多写了
1:SetDBGridShowColus(2);
2:SetDBGridShowColus(4);
3:SetDBGridShowColus(8);
4:SetDBGridShowColus(16);
5:SetDBGridShowColus(32);
end;
end;function TForm1.IntToBin(Value, Size: Integer): String;
var
i: Integer;
begin
Result:='';
for i:=Size-1 downto 0 do
begin
if Value and (1 shl i)<>0 then
begin
Result:=Result+'1';
end
else
begin
Result:=Result+'0';
end;
end;
end;procedure TForm1.SetDBGridShowColus(ch: byte);
var
strtmp:string;
i:Byte;
cls:array[1..6] of Byte;
begin
strtmp:=IntToBin(ch,6);
for i:=1 to Length(strtmp) do
begin
cls[i]:=StrToInt(strtmp[i]);
end;
DBGrid1.Columns[2].Visible:=cls[1]=1;
DBGrid1.Columns[3].Visible:=cls[2]=1;
DBGrid1.Columns[4].Visible:=cls[3]=1;
DBGrid1.Columns[5].Visible:=cls[4]=1;
DBGrid1.Columns[6].Visible:=cls[5]=1;
DBGrid1.Columns[7].Visible:=cls[6]=1;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
//确定保存
{知道了表名、字段名称、姓名等信息、
不要使用insert into ,
需要使用Update student_score set A_score=:A_score where 判断条件
Parameters.ParamByName('id').Value:=strtofloatDef(edit1.text,0.0)}
end;end.