Insert in OleDb does not work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mp

    Insert in OleDb does not work

    I have example like follows:

    OleDbCommand InsertCommand =
    new OleDbCommand("I NSERT INTO RecnikTable VALUES (@ENGLESKI, @SRPSKI)",
    thisConnection) ;
    InsertCommand.P arameters.Add(" @ENGLESKI", OleDbType.VarCh ar);
    InsertCommand.P arameters.Add(" @SRPSKI", OleDbType.VarCh ar);

    string[] reci = {textBox2.Text, textBox2.Text};
    InsertCommand.P arameters["@ENGLESKI"].Value=reci[0];
    InsertCommand.P arameters["@SRPSKI"].Value=reci[1];

    This does not work.

    If I use hard coded values instead reci[0] it does not work too. Interesting
    is, if I use this example like command line project everything works
    perfectly.

    Does somebody know what is wrong?

    Thanks



  • Ron Allen

    #2
    Re: Insert in OleDb does not work

    mp,
    You forgot your fields in the INSERT command. Try
    INSERT INTO RecnikTable field1, field2 VALUES
    using, of course your own field names.

    Ron Allen
    "mp" <plamir@volja.n et> wrote in message
    news:uPfAINy7DH A.1356@tk2msftn gp13.phx.gbl...[color=blue]
    > I have example like follows:
    >
    > OleDbCommand InsertCommand =
    > new OleDbCommand("I NSERT INTO RecnikTable VALUES (@ENGLESKI, @SRPSKI)",
    > thisConnection) ;
    > InsertCommand.P arameters.Add(" @ENGLESKI", OleDbType.VarCh ar);
    > InsertCommand.P arameters.Add(" @SRPSKI", OleDbType.VarCh ar);
    >
    > string[] reci = {textBox2.Text, textBox2.Text};
    > InsertCommand.P arameters["@ENGLESKI"].Value=reci[0];
    > InsertCommand.P arameters["@SRPSKI"].Value=reci[1];
    >
    > This does not work.
    >
    > If I use hard coded values instead reci[0] it does not work too.[/color]
    Interesting[color=blue]
    > is, if I use this example like command line project everything works
    > perfectly.
    >
    > Does somebody know what is wrong?
    >
    > Thanks
    >
    >
    >[/color]


    Comment

    • Michel R.

      #3
      Re: Insert in OleDb does not work

      "Tu-Thach" <tuthach@antisp am.ongtech.com> wrote in message news:<A064C963-FFC5-4AFC-8A91-EA2FDE3CBF86@mi crosoft.com>...[color=blue]
      > OleDb uses ? for parameters instead of @ENGLSKI, @SRPSKI.
      >
      > Tu-Thach
      >
      > ----- mp wrote: -----
      >
      > I have example like follows:
      >
      > OleDbCommand InsertCommand =
      > new OleDbCommand("I NSERT INTO RecnikTable VALUES (@ENGLESKI, @SRPSKI)",
      > thisConnection) ;
      > InsertCommand.P arameters.Add(" @ENGLESKI", OleDbType.VarCh ar);
      > InsertCommand.P arameters.Add(" @SRPSKI", OleDbType.VarCh ar);
      >
      > string[] reci = {textBox2.Text, textBox2.Text};
      > InsertCommand.P arameters["@ENGLESKI"].Value=reci[0];
      > InsertCommand.P arameters["@SRPSKI"].Value=reci[1];
      >
      > This does not work.
      >
      > If I use hard coded values instead reci[0] it does not work too. Interesting
      > is, if I use this example like command line project everything works
      > perfectly.
      >
      > Does somebody know what is wrong?
      >
      > Thanks[/color]


      Maybe you forgot to do an InsertCommand.E xecuteNonQuery at the end of your code???

      Michel

      Comment

      • mp

        #4
        Re: Insert in OleDb does not work

        I am sorry. Here is not solution.
        I am confused because averything works with command line project but not
        with win app.

        Thanks

        "Michel R." <microusseau@vi deotron.ca> wrote in message
        news:8fb2e60c.0 402091510.52829 ac6@posting.goo gle.com...[color=blue]
        > "Tu-Thach" <tuthach@antisp am.ongtech.com> wrote in message[/color]
        news:<A064C963-FFC5-4AFC-8A91-EA2FDE3CBF86@mi crosoft.com>...[color=blue][color=green]
        > > OleDb uses ? for parameters instead of @ENGLSKI, @SRPSKI.
        > >
        > > Tu-Thach
        > >
        > > ----- mp wrote: -----
        > >
        > > I have example like follows:
        > >
        > > OleDbCommand InsertCommand =
        > > new OleDbCommand("I NSERT INTO RecnikTable VALUES (@ENGLESKI,[/color][/color]
        @SRPSKI)",[color=blue][color=green]
        > > thisConnection) ;
        > > InsertCommand.P arameters.Add(" @ENGLESKI", OleDbType.VarCh ar);
        > > InsertCommand.P arameters.Add(" @SRPSKI", OleDbType.VarCh ar);
        > >
        > > string[] reci = {textBox2.Text, textBox2.Text};
        > > InsertCommand.P arameters["@ENGLESKI"].Value=reci[0];
        > > InsertCommand.P arameters["@SRPSKI"].Value=reci[1];
        > >
        > > This does not work.
        > >
        > > If I use hard coded values instead reci[0] it does not work too.[/color][/color]
        Interesting[color=blue][color=green]
        > > is, if I use this example like command line project everything[/color][/color]
        works[color=blue][color=green]
        > > perfectly.
        > >
        > > Does somebody know what is wrong?
        > >
        > > Thanks[/color]
        >
        >
        > Maybe you forgot to do an InsertCommand.E xecuteNonQuery at the end of your[/color]
        code???[color=blue]
        >
        > Michel[/color]


        Comment

        Working...