Adding row to table

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

    #1

    Adding row to table

    Hi there,

    VB 2003 1.1 Access Database, oledb, Windows Application

    I've been trying this for 3 days straight now and CANNOT get this to
    work, im about to go insane because it is soo simple. All I want to do
    is insert a new row !

    I have 1 table 'People'

    In that table I have "Name" and "LastName" Name as primary Key."

    my adapter is called OleDbDataAdapte r1
    my connection is called OleDbConnection 1
    and I have a dataset called DataSet11

    my connection is

    "Me.OleDbConnec tion1.Connectio nString = "Jet OLEDB:Global Partial Bulk
    Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
    "ocking Mode=1;Data Source=""C:\Doc uments and
    Settings\Pig\De sktop\New Folder\TEST" & _
    ".mdb"";Jet OLEDB:Engine
    Type=5;Provider =""Microsoft.Je t.OLEDB.4.0"";J et OLEDB:Syste" & _
    "m database=;Jet OLEDB:SFP=False ;persist security
    info=False;Exte nded Properties=" & _
    ";Mode=Shar e Deny None;Jet OLEDB:Encrypt Database=False; Jet
    OLEDB:Create System D" & _
    "atabase=False; Jet OLEDB:Don't Copy Locale on Compact=False;J et
    OLEDB:Compact Wit" & _
    "hout Replica Repair=False;Us er ID=Admin;Jet OLEDB:Global Bulk
    Transactions=1" "

    if anyone wants that.


    On my form I have 2 text boxes

    "txtname" and "txtlastnam e"
    I also have a button "Button1"

    All I want is for someone to put something in those two text boxes,,
    press the button and for it to add a new Person with those 2 strings.

    So they press the button and it adds a new row to the table, so like
    adding a new person.


    Can someone just tell me/show me how to do this, I'm having soo much
    trouble, since I have asked about 50 people and tried about 50 differnt
    ways and nothing works

    PLEASE HELP ME.

    thanx in advance

  • Cor Ligthert [MVP]

    #2
    Re: Adding row to table

    Bonzol,

    You were writing this in the thread where I asked why you not was using the
    code from GhostAIk had given you.

    This was your answer.[color=blue]
    >yeah, I had a problem with it, and am waiting a reply in that other thread[/color]

    What help do you want if you not tries what somebody gives you as
    suggestion?

    It was nice code for an insert in the way your question is asked.

    Cor

    "Bonzol" <Bonzol@hotmail .com> schreef in bericht
    news:1149319868 .118837.273280@ h76g2000cwa.goo glegroups.com.. .[color=blue]
    > Hi there,
    >
    > VB 2003 1.1 Access Database, oledb, Windows Application
    >
    > I've been trying this for 3 days straight now and CANNOT get this to
    > work, im about to go insane because it is soo simple. All I want to do
    > is insert a new row !
    >
    > I have 1 table 'People'
    >
    > In that table I have "Name" and "LastName" Name as primary Key."
    >
    > my adapter is called OleDbDataAdapte r1
    > my connection is called OleDbConnection 1
    > and I have a dataset called DataSet11
    >
    > my connection is
    >
    > "Me.OleDbConnec tion1.Connectio nString = "Jet OLEDB:Global Partial Bulk
    > Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
    > "ocking Mode=1;Data Source=""C:\Doc uments and
    > Settings\Pig\De sktop\New Folder\TEST" & _
    > ".mdb"";Jet OLEDB:Engine
    > Type=5;Provider =""Microsoft.Je t.OLEDB.4.0"";J et OLEDB:Syste" & _
    > "m database=;Jet OLEDB:SFP=False ;persist security
    > info=False;Exte nded Properties=" & _
    > ";Mode=Shar e Deny None;Jet OLEDB:Encrypt Database=False; Jet
    > OLEDB:Create System D" & _
    > "atabase=False; Jet OLEDB:Don't Copy Locale on Compact=False;J et
    > OLEDB:Compact Wit" & _
    > "hout Replica Repair=False;Us er ID=Admin;Jet OLEDB:Global Bulk
    > Transactions=1" "
    >
    > if anyone wants that.
    >
    >
    > On my form I have 2 text boxes
    >
    > "txtname" and "txtlastnam e"
    > I also have a button "Button1"
    >
    > All I want is for someone to put something in those two text boxes,,
    > press the button and for it to add a new Person with those 2 strings.
    >
    > So they press the button and it adds a new row to the table, so like
    > adding a new person.
    >
    >
    > Can someone just tell me/show me how to do this, I'm having soo much
    > trouble, since I have asked about 50 people and tried about 50 differnt
    > ways and nothing works
    >
    > PLEASE HELP ME.
    >
    > thanx in advance
    >[/color]


    Comment

    • Bonzol

      #3
      Re: Adding row to table

      As I said up the top, I have tried 50 peoples code.

      I couldnt get his code to work.

      Comment

      • Bonzol

        #4
        Re: Adding row to table

        cor,, with regards to his code,

        Dim tConnection As SqlConnection = New
        SqlConnection(y ourConnectionSt ringHere)
        Dim tCommand As SqlCommand = New SqlCommand

        how do I reformat that for an oledb database?

        Comment

        • Bonzol

          #5
          Re: Adding row to table

          I have tried

          ' Dim Conn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
          Source=C:\Docum ents and Settings\Pig\De sktop\New Folder\TEST.mdb ;User
          Id=admin;Passwo rd=;"
          ' Dim tConnection As New OleDb.OleDbConn ection(Conn)
          ' Dim tCommand As New OleDb.OleDbComm and

          but then that stops half the other code from working, since it was
          reffering to SQL and now is not.

          Comment

          • Bonzol

            #6
            Re: Adding row to table

            ok, finally got it for anyone else who wants to know also.
            Some guy on another forum helped. Cheers anyway

            Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
            System.EventArg s) Handles Button1.Click


            Dim Conn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
            Source=C:\Docum ents and Settings\Pig\De sktop\New Folder\TEST.mdb ;User
            Id=admin;Passwo rd=;"
            Dim tConnection As New OleDb.OleDbConn ection(Conn)
            Dim SQL As String = "INSERT INTO People ([Name], [LastName])
            VALUES(@Name, @LastName)" 'The @ Are Parameters
            Dim tCommand As New OleDb.OleDbComm and(SQL, tConnection)

            With tCommand

            'Add Parameter Values

            .Parameters.Add ("@Name", OleDb.OleDbType .VarChar)
            .Parameters(0). Value = txtname.Text
            .Parameters.Add ("@LastName" , OleDb.OleDbType .VarChar)
            .Parameters(1). Value = txtlastname.Tex t

            'Open Connection
            .Connection.Ope n()

            'Execute
            .ExecuteNonQuer y()

            'Close Connection
            .Connection.Clo se()

            End With 'Done with Command


            End Sub

            Comment

            • Cor Ligthert [MVP]

              #7
              Re: Adding row to table

              Bonzol,

              Not another forum this is the code you got from GhostInAk in this forum.

              He was only not using your field names. He left something for you to do
              yourself.

              Why it is his code, because I see seldom using people tCommand as mnemonic
              for a command, mostly it is cmd.

              Cor


              "Bonzol" <Bonzol@hotmail .com> schreef in bericht
              news:1149326547 .576597.196640@ g10g2000cwb.goo glegroups.com.. .[color=blue]
              > ok, finally got it for anyone else who wants to know also.
              > Some guy on another forum helped. Cheers anyway
              >
              > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
              > System.EventArg s) Handles Button1.Click
              >
              >
              > Dim Conn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
              > Source=C:\Docum ents and Settings\Pig\De sktop\New Folder\TEST.mdb ;User
              > Id=admin;Passwo rd=;"
              > Dim tConnection As New OleDb.OleDbConn ection(Conn)
              > Dim SQL As String = "INSERT INTO People ([Name], [LastName])
              > VALUES(@Name, @LastName)" 'The @ Are Parameters
              > Dim tCommand As New OleDb.OleDbComm and(SQL, tConnection)
              >
              > With tCommand
              >
              > 'Add Parameter Values
              >
              > .Parameters.Add ("@Name", OleDb.OleDbType .VarChar)
              > .Parameters(0). Value = txtname.Text
              > .Parameters.Add ("@LastName" , OleDb.OleDbType .VarChar)
              > .Parameters(1). Value = txtlastname.Tex t
              >
              > 'Open Connection
              > .Connection.Ope n()
              >
              > 'Execute
              > .ExecuteNonQuer y()
              >
              > 'Close Connection
              > .Connection.Clo se()
              >
              > End With 'Done with Command
              >
              >
              > End Sub
              >[/color]


              Comment

              • Bonzol

                #8
                Re: Adding row to table

                The code he gave me was for SQL, I seeked help on another forum and
                someone helped me. Don't worry I am very greatful for GhostinAk for
                helping me. But Someone else showed me how to do this


                ..
                Cor Ligthert [MVP] wrote:[color=blue]
                > Bonzol,
                >
                > Not another forum this is the code you got from GhostInAk in this forum.
                >
                > He was only not using your field names. He left something for you to do
                > yourself.
                >
                > Why it is his code, because I see seldom using people tCommand as mnemonic
                > for a command, mostly it is cmd.
                >
                > Cor
                >
                >
                > "Bonzol" <Bonzol@hotmail .com> schreef in bericht
                > news:1149326547 .576597.196640@ g10g2000cwb.goo glegroups.com.. .[color=green]
                > > ok, finally got it for anyone else who wants to know also.
                > > Some guy on another forum helped. Cheers anyway
                > >
                > > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
                > > System.EventArg s) Handles Button1.Click
                > >
                > >
                > > Dim Conn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
                > > Source=C:\Docum ents and Settings\Pig\De sktop\New Folder\TEST.mdb ;User
                > > Id=admin;Passwo rd=;"
                > > Dim tConnection As New OleDb.OleDbConn ection(Conn)
                > > Dim SQL As String = "INSERT INTO People ([Name], [LastName])
                > > VALUES(@Name, @LastName)" 'The @ Are Parameters
                > > Dim tCommand As New OleDb.OleDbComm and(SQL, tConnection)
                > >
                > > With tCommand
                > >
                > > 'Add Parameter Values
                > >
                > > .Parameters.Add ("@Name", OleDb.OleDbType .VarChar)
                > > .Parameters(0). Value = txtname.Text
                > > .Parameters.Add ("@LastName" , OleDb.OleDbType .VarChar)
                > > .Parameters(1). Value = txtlastname.Tex t
                > >
                > > 'Open Connection
                > > .Connection.Ope n()
                > >
                > > 'Execute
                > > .ExecuteNonQuer y()
                > >
                > > 'Close Connection
                > > .Connection.Clo se()
                > >
                > > End With 'Done with Command
                > >
                > >
                > > End Sub
                > >[/color][/color]

                Comment

                • Bonzol

                  #9
                  Re: Adding row to table

                  it probbably happend that way, cause I refernced something from his
                  code to someone else.

                  Comment

                  Working...