Arsip: error insert.... in Ms Acces

 
user image
more 15 years ago

grounders

saya selama ini menggunakan DSN buat koneksi ke Access, dan saya tidak mengalami masalah untuk perintah "insert into" pada SQL. Namun kenapa sewaktu saya rubah koneksinya menggunakan ConnectionString ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' + // provider for Access2000 'Data Source=' + ExtractFilePath(Application.ExeName) + '\Data\Data.mdb;' + // databasefile 'Mode=ReadWrite;' + // set to ReadWrite 'Persist Security Info=False'; kalo saya menggunakan connectionstring selalu keluar error "error in INSERT INTO statement" ada yang tau kenapa bisa keluar error itu jika saya menggunakan connectionstring sedangkan jika menggunakan DSN tidak ada errornya. Info : saya menggunakan Office 2003
user image
more 15 years ago

deLogic

btw, waktu di -open / connect error gak..?? kalo gak salah, hasil dari extractfilepath itu udah termasuk karakter '', jadi '' awal yg di \Data\data.mdb dihapus aja. connectionstirngnya mjd:

ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' + // provider for Access2000
'Data Source=' + ExtractFilePath(Application.ExeName) + 'Data\Data.mdb;' + // databasefile
'Mode=ReadWrite;' + // set to ReadWrite
'Persist Security Info=False';
user image
more 15 years ago

grounders

Waktu di open kayaknya kagak error deh n sukses, tapi ntar saya coba dulu deh thanks.... 12
user image
more 15 years ago

grounders

@deLogic Gimana mas sarannya saya coba tetep kagak berhasil, masih keluar error yang sama. Anehnya error untuk inputan data kagak berhasilnya kalo pakai SQL, tapi kalo saya isikan langsung ke tabel bisa (tanpa menggunakan SQL). Emang SQL yang dipake dengan DSN dan ConnectionString berbeda ya?????
user image
more 15 years ago

deLogic

tidak ada perbedaan syntax SQL antara DSN dan DSN-less. kemungkinan syntax error pada perintah INSERT, untuk itu cek terlebih dahulu perintah INSERT apakah memang sudah benar.
user image
more 15 years ago

grounders

kalo emang sama kenapa kalo saya pake DSN kagak keluar error???? SQLnya: insert into tabel(field1,field2,field3) values(:f1,:f2,:f3);
user image
more 15 years ago

tox2wow

Hmmm, kalo 'Error In INSERT INTO Statement' ya mungkin di sequel Insert nya. [list:503bc0a9f4] insert into tabel(field1,field2,field3) values(:f1,:f2,:f3); [/list:u:503bc0a9f4] coba di ganti menjadi : [list:503bc0a9f4] insert into Nama_Tabel values(:f1,:f2,:f3); [/list:u:503bc0a9f4] :f1,;f2,;f3 itu parameter ya ??? Coba dulu gunakan code tanpa parameter, seperti : [list:503bc0a9f4] insert into Nama_Tabel values(' + QuotedStr(Edit1.text) + ',' + QuotedStr(Edit2.text) + ',' + QuotedStr(Edit3.text) + ')' [/list:u:503bc0a9f4] Kalo memang masih error, coba dulu sintaks Insert nya di Query Ms Access ... Well, selamat mencoba ... :lol:
user image
more 15 years ago

cyber_hecker

yup.. mo make dns atau gak gak ada masalah sama sekali. gue ngeliat kok jadi penasaran seh. makanya gue coba. ternyata gak ada masalah sama sekali. semua berjalan normal. coba perhatikan listing program dibawah ini : kode untuk Form :
object FTest: TFTest
  Left = 192
  Top = 107
  Width = 509
  Height = 477
  Caption = 'FTest'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 16
  object Label1: TLabel
    Left = 16
    Top = 8
    Width = 47
    Height = 16
    Caption = 'Field 1 :'
  end
  object Label2: TLabel
    Left = 16
    Top = 32
    Width = 47
    Height = 16
    Caption = 'Field 2 :'
  end
  object Label3: TLabel
    Left = 16
    Top = 56
    Width = 47
    Height = 16
    Caption = 'Field 3 :'
  end
  object DBGrid1: TDBGrid
    Left = 8
    Top = 104
    Width = 489
    Height = 337
    DataSource = dsTampil
    TabOrder = 0
    TitleFont.Charset = ANSI_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -13
    TitleFont.Name = 'Tahoma'
    TitleFont.Style = []
    Columns = <
      item
        Expanded = False
        FieldName = 'Field1'
        Width = 141
        Visible = True
      end
      item
        Expanded = False
        FieldName = 'Field2'
        Width = 162
        Visible = True
      end
      item
        Expanded = False
        FieldName = 'Field3'
        Width = 71
        Visible = True
      end>
  end
  object Edit1: TEdit
    Left = 80
    Top = 8
    Width = 121
    Height = 22
    Ctl3D = False
    ParentCtl3D = False
    TabOrder = 1
  end
  object Edit2: TEdit
    Left = 80
    Top = 32
    Width = 121
    Height = 22
    Ctl3D = False
    ParentCtl3D = False
    TabOrder = 2
  end
  object SpinEdit1: TSpinEdit
    Left = 80
    Top = 56
    Width = 121
    Height = 23
    Ctl3D = False
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -12
    Font.Name = 'Tahoma'
    Font.Style = []
    MaxValue = 0
    MinValue = 0
    ParentCtl3D = False
    ParentFont = False
    TabOrder = 3
    Value = 0
  end
  object btnSimpan: TBitBtn
    Left = 416
    Top = 8
    Width = 75
    Height = 33
    Caption = '&Simpan'
    TabOrder = 4
    OnClick = btnSimpanClick
  end
  object ADOCon: TADOConnection
    Connected = True
    ConnectionString = 
      'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Se' +
      'ttings\rssa\My Documents\db1.mdb;Persist Security Info=False;Jet' +
      ' OLEDB:Database Password=a'
    LoginPrompt = False
    Mode = cmShareDenyNone
    Provider = 'Microsoft.Jet.OLEDB.4.0'
    Left = 352
    Top = 376
  end
  object QTampil: TADOQuery
    Active = True
    Connection = ADOCon
    CursorType = ctStatic
    Parameters = <>
    SQL.Strings = (
      'SELECT Field1, Field2, Field3 FROM TTest')
    Left = 400
    Top = 376
    object QTampilField1: TWideStringField
      FieldName = 'Field1'
      Size = 50
    end
    object QTampilField2: TWideStringField
      FieldName = 'Field2'
      Size = 50
    end
    object QTampilField3: TIntegerField
      FieldName = 'Field3'
      DisplayFormat = '#,##0.##'
    end
  end
  object QInsert: TADOQuery
    Connection = ADOCon
    Parameters = <>
    Left = 448
    Top = 376
  end
  object dsTampil: TDataSource
    DataSet = QTampil
    Left = 408
    Top = 392
  end
end
kode untuk Unit :
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Spin, Grids, DBGrids, DB, ADODB;
type
  TFTest = class(TForm)
    ADOCon: TADOConnection;
    QTampil: TADOQuery;
    QInsert: TADOQuery;
    QTampilField1: TWideStringField;
    QTampilField2: TWideStringField;
    QTampilField3: TIntegerField;
    dsTampil: TDataSource;
    DBGrid1: TDBGrid;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    SpinEdit1: TSpinEdit;
    btnSimpan: TBitBtn;
    procedure btnSimpanClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  FTest: TFTest;
implementation
{$R *.dfm}
procedure TFTest.btnSimpanClick(Sender: TObject);
begin
  with QInsert do begin
    SQL.Clear;
    SQL.Append('INSERT INTO TTest(Field1, Field2, Field3) VALUES (:F1, :F2, :F3)');
    Parameters[0].Value := Edit1.Text;
    Parameters[1].Value := Edit2.Text;
    Parameters[2].Value := SpinEdit1.Text;
    try
      ExecSQL;
      QTampil.Requery();
    except
      on e: exception do
        ShowMessage(e.ClassName+#10#13+e.Message);
    end;
  end;
end;
end.
hasilnya : gak ada masalah sama sekali kok. nb : ini menggunakan database access 2000 yang ada passwordnya. habis lagi males mbikin database baru. mungkin kalo membandingkan dengan koneksi yang dibuat, pada bagian "database password" pada connectionstring harusnya nggak ada.
more ...
  • Pages:
  • 1
Share to

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com