I am just getting VB.NET and Access talking for the first time and I cannot get this INSERT SQL code to work:
This is causing build errorPHP 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
I have a text entry in Form1 called txtNewCompany and if I tryC:\MyPrograms\ConnectAccess\Form1.vb(153): Operator '&' is not defined for types 'String' and 'System.Windows.Forms.TextBox'.
the actual string 'txtNewCompany'goes into ther table, not the valuePHP Code:Dim strSQL As String = "INSERT INTO Companies(CompanyName) VALUES('txtNewCompany')"
Any help much appreciated


Reply With Quote