Search A DataSet

  • Thread starter Thread starter tracer
  • Start date Start date
T

tracer

I have created a DataSet from a MySQL db using the ByteFX fxns,
however now that I have my dataset how do I search within that
dataset?

Basically I need to search a non-primary key against an array,
found/matched records will be updated, and unfound records will be
inserted/created.

If someone can post some sample code, or point me towards a good
DataSet tutorial It would be greatly appreciated.
 
Hi Tracer,

Have a look at the datatable.select

Or/and at the

Dataview.rowfilter

I prefer the last (and to make it faster do a dataview.sort before that)

They both can do what you want.

I hope this helps?

Cor
 
That helps a little, here is my code.....Maybe you could be more
specific?



' Define the MySQL Connection
Dim myConnString As String
myConnString = "Database=myDB;Data Source=localhost;User
Id=myUser;Password=myPW "
Dim mySelectQuery As String
mySelectQuery = "SELECT * FROM palm_contacts WHERE empID
=1"
Dim myConn As New
ByteFX.Data.MySqlClient.MySqlConnection(myConnString)
Dim myAdapter As New ByteFX.Data.MySqlClient.MySqlDataAdapter
myAdapter.SelectCommand = New
ByteFX.Data.MySqlClient.MySqlCommand(mySelectQuery, myConn)
Dim cb As ByteFX.Data.MySqlClient.MySqlCommandBuilder = New
ByteFX.Data.MySqlClient.MySqlCommandBuilder(myAdapter)
myConn.Open()

Dim ds As DataSet = New DataSet
Dim myTable As String
myTable = "palm_contacts"
myAdapter.Fill(ds, myTable)

' Set a Counter for the MySQL DataSet Loop
Dim yRecords As Int
yRecords = 0

' While yRecords < xRecords LOOP
Dim palmID As String
For Each palmID In pID
yRecords = yRecords + 1

' Select PalmID From MySQL DataSet

' If Not Found In MySQL DataSet
' INSERT NEW ROW

' If Found In MySQL DataSet
' UPDATE existing row

Next
 
Hi Tracer

An answer in the style you started with and one with the dataview
All is typed here so watch typos or other errors, have for using the
dataview fields a look in MSDN. (And when you do not succeed in that,
message than again, but with a new sample that you did make therefore)

I hope this helps a little bit?

Cor

'2003 style
\\\With what you started
for i as integer = 0 to ds.tables(0).rows.count - 1
if ds.tables(0).rows(i).item("palmID") = "xxxx" then
'Insert new row bla bla
end if
end for
///
Or
\\\With the dataview
'After the fill
dim dv as new dataview(ds.tables(0))
dv.sort = "palmID"
dv.rowfilter = "palmID = xxxx"
for i as integer = 0 to dv(i).count - 1
' Insert new row bla bla
end if
////
 
Hi,

these operation go via DataTable. You may want to check DataTable's
LoadDataRow method. It has the capability to find & update and in case of
missing row, to insert (and it takes values as an array).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


I have created a DataSet from a MySQL db using the ByteFX fxns,
however now that I have my dataset how do I search within that
dataset?

Basically I need to search a non-primary key against an array,
found/matched records will be updated, and unfound records will be
inserted/created.

If someone can post some sample code, or point me towards a good
DataSet tutorial It would be greatly appreciated.
 
Back
Top