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.Object, ByVal e As System.EventArgs) Handles 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(strSQL, myConnectionString)
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
Quote:
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