Debugging Error

6 views
Skip to first unread message

Ehtisham Inam

unread,
May 9, 2014, 12:07:58 AM5/9/14
to
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__

unread,
May 9, 2014, 2:06:50 AM5/9/14
to
Ehtisham Inam wrote:

> 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]

> 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.
Reply all
Reply to author
Forward
0 new messages