CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    1

    Exclamation Items Not Adding to Database VS2010

    I am trying to add items to my database. I can not seem to figure this out.
    The code I have executes without errors, but the items just fail to appear in
    the database. Please help! (and thanks in advance) The following is the only
    code I have in my form. I have tried the SQL command with and without the ;


    Code:
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Connection As New OleDb.OleDbConnection
            Connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database2.accdb;"
            Dim newrecord As New System.Data.OleDb.OleDbCommand 'declare the sql command
    
    
            newrecord.CommandText = "INSERT INTO Users ([Email], [PWD], [FirstName], [LastName]) VALUES ('Reid', 'aa', 'bb', 'cc')" 'put together the command string
            newrecord.Connection = Connection 'provide the newrecord with the connection info
    
            Connection.Open() 'open the connection to to the database
    
            newrecord.ExecuteNonQuery() 'execdute the command
    
            Connection.Close()
            MessageBox.Show("OKAY")
        End Sub
    My form looks like this.



    Thank you for all your help!!!,
    Reid Kersey

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Items Not Adding to Database VS2010

    Find someone that has Access, and can also connect to your db (if you don't)
    Paste the query into SQL EDITOR and hit EXECUTE.
    Code:
    INSERT INTO Users ([email], [PWD], [FirstName], [LastName]) VALUES ('Reid', 'aa', 'bb', 'cc')"
    Access is a lot less forgiving, and points to the offending character;.

    Also, check your DATATYPES.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Items Not Adding to Database VS2010

    Okay, i'm using SQL and import System.Data.SqlClient..

    and i always have to specify the Command type...

    ie:
    Code:
    newrecord.CommandType = CommandType.Text
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Items Not Adding to Database VS2010

    Beacuse you are "new" to database programming, why not consider using parameterized queries. They are very much easier to manipulate, and instead of having ten INSERT INTO statements, you could have only one.

    Just trying to help you "grow" that is all...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured