SQl insert into help-VBForums
Results 1 to 4 of 4

Thread: SQl insert into help

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2016
    Posts
    6

    SQl insert into help

    I'm all new to coding still and only really know what i've been taught in college for our projects. For this one we needed to connect to a database and be able to select, update, delete, and insert into a table for whatever we're doing. With the code I have now I can select from the table and it works but I cannot insert into it, I think I might have messed up the code for it or at least I hope I did because other then that I'd have no idea what would be wrong. I have the access file saved in the debug file where it normally works for update and selecting. Heres my code so far, again it's pretty basic. I am saving this as 2010 visual studio's but using 2015 to edit it just because apparently it needs to be 2010 for it to be marked but the file will load in 2015 and will be saved in 2010 normally. Idk if that might have anything to do with it but you might?

    Public Class Newuservb
    Dim Connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database1.accdb")
    Dim dt As New DataTable
    Dim DataAdapter As New OleDb.OleDbDataAdapter
    Dim TableSearchUser As Integer
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Logins.Close()
    End Sub

    Private Sub Newuservb_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
    Dim username As String
    Dim password As String
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    username = TextBox1.Text
    password = TextBox2.Text

    Connection.Open()

    DataAdapter = New OleDb.OleDbDataAdapter("INSERT INTO Table1 ([UserName], [Password]) VALUES ('" & username & "' , '" & password & "') ", Connection)

    Connection.Close()



    End Sub
    End Class
    I've tried changing the column names from username and password but it doesn't make a difference. No error comes up and it doesn't crash at all it just won't show up in the database.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,272

    Re: SQl insert into help

    DataAdaptors are for getting information BACK ... they are not intended to be used with Action Queries (Insert, Update, Delete... basically actions that do not return data).

    You should instead use a Command object, set the commandtext property, then use the ExecuteNonQuery method of the command...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2016
    Posts
    6

    Re: SQl insert into help

    I see, do you know of any sites or videos, even examples which can show this which aren't too complicated? I've been looking for a while and can't find anything useful as it's normally too complicated or really long to the point of me getting confused,

    or am I looking too into it and it's actually really simple?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,272

    Re: SQl insert into help

    It's simpler than it sounds ...
    Just start here:
    http://www.vbforums.com/showthread.p...ed-May-13-2011

    there's some stuff that isn't going to be relevant, some stuff that will... on that thread though, there should be apost, or a link to a post about conencting and executing action queries.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.