Problems with Simple DataBindings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got problems with databindings in a windows forms application. I've
wrote a component with a class (Article) with a public method
(GetArticlesByRef) that returns a typed Dataset.

This is the method:

Public Function GetArticlesByRef(ByVal pRef As Integer) As dsArticles
Dim strSQL As String = "SELECT * FROM Articles WHERE ART_REF = @Ref"
Dim con As New SqlConnection("Data Source=(local);Integrated
Security=SSPI;Initial Catalog=eShop")
Dim cmd As New SqlCommand(strSQL, con)
cmd.Parameters.Add(New SqlParameter("@Ref", SqlDbType.Int, 4))
cmd.Parameters("@Ref").Value = pRef
Dim da As New SqlDataAdapter(cmd)
da.TableMappings.Add("Table", "dsArticles")
Dim ds As New dsArticles
da.Fill(ds)
Return ds
End Function

In the windows forms i've added a typed dataset (dsArticles1), two TextBox
and one button controls. In the first textbox the user enters a ref code. The
second textbox is binded to the olumn ART_DESCRIPTION of the table Articles
in the Dataset. Next is the code of the click event of the button:

Dim art As New Article
DsArticles1.Clear()
DsArticles1 = art.GetArticlesByRef(Ctype(TextBox1.Text, Integer))

When I run the application, the bind doesn't work. It Only works if I add a
typed Dataset to the form and i load it from a SQLDataadapter. The problem is
when i use a component.

Thanks in advance.
 
Hi Chema,

Make sure you retrieve the data first and then do the binding. It might mean
you will have to move the binding code from the Designer region to another
place which is executed after the call to GetArticlesByRef.
 
Back
Top