Recordsets in Vb.net ?

  • Thread starter Thread starter Mobile Boy 36
  • Start date Start date
M

Mobile Boy 36

How can I retrieve a set of records from a SqlserverCe table with (for
example) 4 fields?
Can someone post a piece of code please?

Let 's assume:

Customer

Nr Name Street City
1 Jack Pocketstreet Washington
2 Peter Downingstreet New York

I want to view the fields in 4 textboxes... (txtNr, txtName, txtStreet and
txtCity).
I have to be able to scroll through the records.

In the old fashioned evb (and vb 5....) you had recordsets...
What do you have in stead of it in Vb.net ?
Please don't give a complex description...A simple code example would be
more effective

best regards,
Mobile Boy
 
Use the SqlCeDataAdapter to bring back a DataSet. There are plenty of
samples online for how to do this, so start with Google.

-Chris
 
At a minimum you'll need three objects, a DataAdapter, a Command and
Connection

Technically the Command object can be inferred by using the SelectCommand
Property of the DataAdapter. SO basically it'd be something like:

Dim cn as SqlCeConnection = new SqlCeConnection("YourConnectionString")
Dim cmd as SqlCeCommand = new SqlCeCommand("SELECT Nr, Name, Street, City
FROM SomeTable", cn)
'I'd recommend against using Name as a field name but that's just a matter
of preference.

Dim da as SqlCeDataAdapter = new SqlCeDataAdapter(cmd)
Dim ds as New DataSet
da.Fill(ds, "NameYouWantTheTableToHave")

So instead of a recordset you now have a DataSet with one table...you could
also just use a DataTable...same effect in the end.
Then bind the textBoxes.
tbName.DataBindings.Add("Text", ds, "Nr") where "Text" is the name of the
property you want to bind to.

Simililary you can use a DataReader but in this instance I don't think it's
what you want.

Let me know if you have any problems.

Cheers,

Bill
 
Back
Top