ssql:='intert into student values('+''''+db_studentid.text+''''+','+''''+db_name.text+''''+','+''''+com_sex.text+''''+','+''''+DBCom_department.text+''''+','+''''+DBCom_class.text+''''+','+FormatDateTime('yyyy-mm-dd',DBDate_birthdaty.Date)+','+''''+DB_native_place.text+'''')';
当然了,你不说怎么知道 要这么写对好了!!!!!!!看是什么不同。 var str1:string; str1:=formatDatetime(FormatDateTime('yyyy-mm-dd',DBDate_birthdaty.Date); ssql:='insert into student1 values('+''''+db_studentid.text+''''+','+''''+db_name.text+''''+','+''''+c+om_sex.text+''''+','+''''+inttostr(DBCom_department.text)+''''+','+''''+DBCom_class.text+''''+','+''''+str1+''''+','+''''+DB_native_place.text+''''+')';
str1:=FormatDateTime('yyyy-mm-dd',DBDate_birthdaty.Date); 这一句还是报错啊 [Error] student_add.pas(64): Undeclared identifier: 'Date' [Error] student_add.pas(65): Undeclared identifier: 'ssql' [Error] student_add.pas(65): Undeclared identifier: 'c' [Error] student_add.pas(65): There is no overloaded version of 'IntToStr' that can be called with these arguments
老兄,好像应该是这样哦, insert into table()vause() insert into talbe1 select * from table2
用这个SQL试试吧: insert into student1 (字段1,字段2,.....) values (值1,值2,.....) 你可能是字段与输入值不匹配。
没有看你的SQL语句,分析一下你的错误 [Error] student_add.pas(64): Undeclared identifier: 'Date' [Error] student_add.pas(65): Undeclared identifier: 'ssql' [Error] student_add.pas(65): Undeclared identifier: 'c'ssql,c,date没有定义,仔细查一下[Error] student_add.pas(65): There is no overloaded version of 'IntToStr' that can be called with these arguments指 inttostr(DBCom_department.text)这一段,Text是字符串型
我没有抄啊,我正在改成这样还是错啊 ssql:='insert into student(studentid,name,sex,class_id,department_id) values('+''''+DB_studentid.text+''''+','+''''+db_name.text+''''+','+''''+com_sex.text+''''+','+''''+dbcom_class.text+''''+','+''''+inttostr(dbcom_department.text)+''''+')'; 错误为:[Error] student_add.pas(71): There is no overloaded version of 'IntToStr' that can be called with these arguments 但department_id是smallint型的
ssql:='insert into student studentid,name,sex,class_id,department_id) values('''+DB_studentid.text+'''+','''+db_name.text+''','''+com_sex.text+''','''+dbcom_class.text+''','+dbcom_department.text+')'; 这样写是对的,但是插不了数据,但我知道是什么怪问题了,是控件的原因,dbcom_department.text是DBLookupComboBox1控件,其实这个控件绑定是department_id是数值型,而显示的是department_name字符型, 怪不得要不报错,要不插不进数据来。 可是我该怎么办啊??
var db_Cbo : TDBLookupComboBox ; begin db_Cbo := dbCom_Department ; showmessage(db_cbo.ListSource.DataSet.Fields[cb_cbo.ListFieldIndex].AsString) ; end ;看看结果吧。
你试试不要指定列。 ssql:='insert into strdent values(...对应所有列的值...);
cookieyfeng说的是对的
insert写错了最后应该是''''+')';应该是values
请前辈们帮我指正啊
要这么写对好了!!!!!!!看是什么不同。
var
str1:string;
str1:=formatDatetime(FormatDateTime('yyyy-mm-dd',DBDate_birthdaty.Date);
ssql:='insert into student1 values('+''''+db_studentid.text+''''+','+''''+db_name.text+''''+','+''''+c+om_sex.text+''''+','+''''+inttostr(DBCom_department.text)+''''+','+''''+DBCom_class.text+''''+','+''''+str1+''''+','+''''+DB_native_place.text+''''+')';
str1:=FormatDateTime('yyyy-mm-dd',DBDate_birthdaty.Date);
这一句还是报错啊
[Error] student_add.pas(64): Undeclared identifier: 'Date'
[Error] student_add.pas(65): Undeclared identifier: 'ssql'
[Error] student_add.pas(65): Undeclared identifier: 'c'
[Error] student_add.pas(65): There is no overloaded version of 'IntToStr' that can be called with these arguments
insert into table()vause()
insert into talbe1 select * from table2
ssql := Format(
'intert into student'#13#10 +
'values(%s,%s,%s,%s,%s,%s,%s)',
[QuotedStr(db_studentid.text), QuotedStr(db_name.text),
QuotedStr(com_sex.text), QuotedStr(DBCom_department.text),
QuotedStr(DBCom_class.text),
QuotedStr(FormatDateTime('yyyy-mm-dd', DBDate_birthdaty.Field.AsDateTime)),
QuotedStr(DB_native_place.text)])
insert into student1
(字段1,字段2,.....)
values
(值1,值2,.....)
你可能是字段与输入值不匹配。
[Error] student_add.pas(64): Undeclared identifier: 'Date'
[Error] student_add.pas(65): Undeclared identifier: 'ssql'
[Error] student_add.pas(65): Undeclared identifier: 'c'ssql,c,date没有定义,仔细查一下[Error] student_add.pas(65): There is no overloaded version of 'IntToStr' that can be called with these arguments指 inttostr(DBCom_department.text)这一段,Text是字符串型
首先:DBDate_birthdaty.Date不能这么起名字,在你的数据库表中把名字
改为dbdate_birthdaty_date
第2:你自己写的ssql要在开始时定义:var ssql:string;
第3:我给你的程序第7行写的时候不小心多了个加号c+om_sex改为com_sex
第4:你说你的DBCom_department.text为smallint呀,怎么会是字符型呢?
如果是字符型就把inttostr(DBCom_department.text)改为
DBCom_department.text
ssql:='insert into student(studentid,name,sex,class_id,department_id) values('+''''+DB_studentid.text+''''+','+''''+db_name.text+''''+','+''''+com_sex.text+''''+','+''''+dbcom_class.text+''''+','+''''+inttostr(dbcom_department.text)+''''+')';
错误为:[Error] student_add.pas(71): There is no overloaded version of 'IntToStr' that can be called with these arguments
但department_id是smallint型的
showmessage(str)
通过测试,便可知道的你的拼接是否有错?
原则:
1、自增量型在插入时,无需给出;
2、数值型无需引号;
3、日期型一定要转化;
代码改为:
ssql:='insert into student studentid,name,sex,class_id,department_id) values('''+DB_studentid.text+'''+','''+db_name.text+''','''+com_sex.text+''','''+dbcom_class.text+''','+dbcom_department.text+')';
注意:
dbcom_department.text必需作输入限制,否则无法保证数据库的完整性,又会报错!!!!切记!!!
ssql:='insert into student(studentid,name,sex,class_id,department_id)
values(:studentid,:name,:sex,class_id,:department_id);
query1.sql.clear;
query1.sql.add(ssql);
query1.parambyname('student_id').asstring:=DB_studentid.text;
query1.parambyname('name').asstring:=DB_name.text;
...........
这样试试
这样写是对的,但是插不了数据,但我知道是什么怪问题了,是控件的原因,dbcom_department.text是DBLookupComboBox1控件,其实这个控件绑定是department_id是数值型,而显示的是department_name字符型,
怪不得要不报错,要不插不进数据来。
可是我该怎么办啊??
db_Cbo : TDBLookupComboBox ;
begin
db_Cbo := dbCom_Department ;
showmessage(db_cbo.ListSource.DataSet.Fields[cb_cbo.ListFieldIndex].AsString) ;
end ;看看结果吧。
ssql:='insert into strdent values(...对应所有列的值...);
那么:query1.fieldbyname('department_id').asinteger
linx88(haozi)大侠,你说的不指定列是可行的。可我....
其实这个控件里的数据设置一共有2个地方,
1 作为普通的DB控件,它需要设置对应的DataSource和DataField
2 作为一个下拉框,它需要说明下拉框里的数据来源,包括ListSource和
ListField(ListFieldIndex),还有一个地方就是keyField,它说明了实际
加入到DataField里的数据 是 ListSource 里的哪个 Field,也就是说,
你可以在界面上显示一个 名称 ,而实际加入数据库的是 对应的 ID,这
正是你所需要的。
你需要做的就是检查你的DBLookupComboBox的keyField 属性 ,看看是不是
指到了和department_name 相对应的id 上。
如果一切ok,就可以通过
dbcom_department.ListSource.DataSet.
FieldbyName(dbcom_department.keyfield).AsString
来得到当前选中的id.
上面的帖子是我写错了,sorry