1、query1.SQL.Add('Insert into CONTACT values('quotedstr(combobox2.Text)+','+DateTimePicker1.date')');
以上是我的部分SQL代码,我的数据库对应字段的数据类型是date,在我执行query1.execsql;的时候,系统提示我,string 和date是不能共存的...请问各位大哥,我这段代码该怎么写呢?2、query1.SQL.Add('select * from cantact where constact_id='+edit1.Text');  CONSTZCT_ID数据类型为number,这段代码运行的时候也不能编译...query1.SQL.Add('select * from cantact where constact_id='?????);  请问问号处我该怎么写呢?谢谢!!

解决方案 »

  1.   

    2:query1.SQL.Add('select * from cantact where constact_id='+edit1.Text);
    1:如果数据库是sql server
      query1.SQL.Add('Insert into CONTACT values('+combobox2.Text+','''+datetostr(DateTimePicker1.date)+''')');
    如果数据库是access
      query1.SQL.Add('Insert into CONTACT values('+combobox2.Text+',#'+datetostr(DateTimePicker1.date)+'#)');PS:我认为你的CONTACT数据表的第一字段为number型
      

  2.   

    1、query1.SQL.Add('Insert into CONTACT values('quotedstr(combobox2.Text)+','+DateTimePicker1.date')'); 
    以上是我的部分SQL代码,我的数据库对应字段的数据类型是date,在我执行query1.execsql;的时候,系统提示我,string 和date是不能共存的...请问各位大哥,我这段代码该怎么写呢? 
    ================================
    query1.SQL.Add('Insert into CONTACT values(' + quotedstr(combobox2.Text)+','+ DateTimeTostr(DateTimePicker1.date) + ')'); 
    2、query1.SQL.Add('select * from cantact where constact_id='+edit1.Text');  CONSTZCT_ID数据类型为number,这段代码运行的时候也不能编译...query1.SQL.Add('select * from cantact where constact_id='?????);  请问问号处我该怎么写呢? 
    ================================
    query1.SQL.Add('select * from cantact where constact_id=' + edit1.text);
      

  3.   

    谢谢你的先
    哈哈,第一字段肯定是number型撒,哪个只是部分操作代码...1、我用的oracle,这个咋整?
    2、query1.SQL.Add('select * from cantact where constact_id='+edit1.Text);这个刚才打错了,我的代码就是这段,但是查询的时候就是要出错...哎~感觉oracle数据库字段的数据类型有点和delphi的组件输出数据类型好多不搭...也转换不过去...是不是我这手太新了,哈哈
      

  4.   

    2、query1.SQL.Add('select * from cantact where constact_id='+edit1.Text);这个刚才打错了,我的代码就是这段,但是查询的时候就是要出错... //出什么错?
      

  5.   

    1、query1.SQL.Add('Insert into CONTACT values('+quotedstr(combobox2.Text)+', '+datetostr(DateTimePicker1.date)+' )'); 
    2. query1.SQL.Add('select * from cantact where constact_id='+quotedstr(edit1.Text)); 
      

  6.   

    query1.sql.text := 'Insert into CONTACT  values(:a1,:a2)';
    query1.parameters.parambyname('a1').value := combobox2.text;
    query1.parameters.parambyname('a2').value := datetimepicker1.date;
    query1.execsql;这样试试
      

  7.   

    1、query1.SQL.Add('Insert into CONTACT values('+quotedstr(combobox2.Text)+', '+datetostr(DateTimePicker1.date)+' )');
    执行的时候错误:数据类型为date得到的却是number  求解决!!!回复SuperTitan001:我说的哪个错误我也忘了,但是肯定出现过!
      

  8.   


    不知道这个能不能解决问题,但是还是要谢谢你。因为我后面生成报表按时间查询的时候,肯定会遇到我提出的问题,所以我想就按照我的那种方法去添加数据  就是不知道有人知道怎么解决么?我的是ORACLE数据库
      

  9.   

    datetostr(DateTimePicker1.date) 这个改一下formatdatetime('yyyy-mm-dd hh:mi:ss',datetimepicker1.date)
      

  10.   


    用的是oracle的数据库
    方法1:
    query1.sql.text := 'Insert into CONTACT  values(:a1,:a2)'; 
    query1.parameters.parambyname('a1').value := combobox2.text; 
    query1.parameters.parambyname('a2').value := datetimepicker1.date; 
    query1.execsql; 方法2:
       with qry1 do
       begin
         close;
         sql.text := ' Insert into CONTACT values('+quotedstr(cbb1.Text)+','+
                     ' to_date('''+FormatDateTime('yyyy-mm-dd hh:mi:ss',datetimepicker1.date)+''',''yyyy-mm-dd hh:mi:ss''))';
         ExecSQL;
       end;要用到to_date函数转换一下