Debugging Error


E

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

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
 
Ad

Advertisements

A

Auric__

Ehtisham said:
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 & _
"')"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top