Results 1 to 3 of 3

Thread: Easy Newb Q: INSERT into Access

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Cork, Ireland
    Posts
    14

    Easy Newb Q: INSERT into Access

    I am just getting VB.NET and Access talking for the first time and I cannot get this INSERT SQL code to work:
    PHP Code:
        Public Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles btnAdd.Click

            Dim strDSN 
    As String "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\temp\PayeRoll.mdb"

            
    Dim strSQL As String "INSERT INTO Companies(CompanyName) VALUES('" txtNewCompany "')"

            ' create Objects of ADOConnection and ADOCommand 
            Dim myConnectionString As New OleDbConnection(strDSN) '
            
    Dim myQuery As New OleDbCommand(strSQLmyConnectionString)

            Try
                
    myConnectionString.Open()
                
    myQuery.ExecuteNonQuery()
            Catch 
    myError As Exception
                MsgBox
    ("Uh oh! Something wrong!")
            Finally
                
    myConnectionString.Close()
                
    ClearCompanies()
                
    GetCompanies()
            
    End Try

        
    End Sub 
    This is causing build error
    C:\MyPrograms\ConnectAccess\Form1.vb(153): Operator '&' is not defined for types 'String' and 'System.Windows.Forms.TextBox'.
    I have a text entry in Form1 called txtNewCompany and if I try
    PHP Code:
    Dim strSQL As String "INSERT INTO Companies(CompanyName) VALUES('txtNewCompany')" 
    the actual string 'txtNewCompany'goes into ther table, not the value

    Any help much appreciated

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    You have to use txtNewCompany,text. You can't shortcut in .Net and leave off the .text.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Cork, Ireland
    Posts
    14
    Thank you that did it.

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