Databindings returns Argument exception

L

Loic

HI there, I hope someone can help.

I am doing this application on a pocket pc where you type a product
number and it returns several values that are taken from an sqlce
database.

What happens is that when I click the Search button the first time it
returns the values from the database alright, but the second time it
returns an Argument Exception error. I think it is the textbox
databinding that I am not doing right, because if I rem out the line
there is no error.

See simplified code below. I have hardcoded the productnumber.

Thanks in advance for any help

Loic


Imports System
Imports System.Windows.Forms
Imports System.Data.SqlServerCe
Imports System.IO



Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Dim cn As SqlCeConnection
Dim barcode As String

Try
barcode = TextBox1.Text
cn = New SqlCeConnection("data source=\Storage
Card\FinalCe.sdf;SSCE:database Password=")
cn.Open()

Dim da As New SqlCeDataAdapter("select sku from salesce
where autoitemno=243429", cn)
Dim ds As New DataSet
da.Fill(ds)
TextBox2.Enabled = False
TextBox2.DataBindings.Add("Text", ds.Tables(0), "sku")

Catch sqlex As SqlCeException
Dim SqlError As SqlCeError

For Each SqlError In sqlex.Errors
MessageBox.Show(SqlError.Message)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
TextBox2.Enabled = True
If cn.State <> ConnectionState.Closed Then
cn.Close()
End If
End Try

End Sub
 
I

Ilya Tumanov [MS]

You can only add binding ones, that's why it failing second time.

In this case you do not need data binding nor do you need a dataset.
Since all you need is a single value, consider using SqlCeDataReader to get
it and assign value to TextBox.Text directly.

Or, you can remove binding before adding it again.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

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