Discussion:
Debugging Error
(too old to reply)
Ehtisham Inam
2014-05-09 04:07:58 UTC
Permalink
Hi guys: Can any one please help me out in this error? Thanks
Error 1 Operator '&' is not defined for types 'String' and 'System.Windows.Forms.TextBox'. C:\Users\kathy\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 20 20 WindowsApplication1

Imports System.Data.OleDb
Public Class Form1
Public connection As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\kathy\Desktop\generalledger.accdb"
Public conn As New OleDbConnection

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.ConnectionString = connection
If conn.State = ConnectionState.Closed Then
conn.Open()
MsgBox("Open")
Else
MsgBox("Closed")

End If

End Sub

Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
Dim sqlQuery As String
sqlQuery = "insert into voucher(VoucherName, Account_Code, Amount) values ('" & TxtVoucher & "', " & TxtAmount & ", '" & TxtAccount & "')"
Dim sqlcommand As New OleDbCommand
With sqlcommand
.CommandText = sqlQuery
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("Save")

End Sub
End Class
Auric__
2014-05-09 06:06:50 UTC
Permalink
Post by Ehtisham Inam
Hi guys: Can any one please help me out in this error? Thanks
Error 1 Operator '&' is not defined for types 'String' and
'System.Windows.Forms.TextBox'.
C:\Users\kathy\AppData\Local\Temporary
Projects\WindowsApplication1\Form1.vb 20 20
WindowsApplication1
[snip]
Post by Ehtisham Inam
sqlQuery = "insert into voucher(VoucherName, Account_Code, Amount)
values ('" & TxtVoucher & "', " & TxtAmount & ", '" & TxtAccount & "')"
Change the above line to this:

sqlQuery = _
"insert into voucher(VoucherName, Account_Code, Amount) values ('" & _
TxtVoucher.Text & "', " & TxtAmount.Text & ", '" & TxtAccount.Text & _
"')"
--
The measure of friendship isn't your ability to not harm, but your capacity
to forgive the things done to you and ask forgiveness for your mistakes.
Loading...