473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

ado.net - find record

Ok, I have the following code. Does any one know how I go about taking this
record set and trying to find if a record exits in it? - Thanks Dale

Imports System.Data.SqlClient

Public Module modLoadDefaults

Public gCONN As New SqlConnection
Public gbMakeConnection As Boolean
Public rsUsers As New Data.DataTable("Users")

Private Function MakeConnection() As SqlConnection

If gCONN.State <> ConnectionState.Open Then
With gCONN
.ConnectionString = "Integrated Security=TRUE;Initial
Catalog=SQL_Test;Data Source=SERVER\SQLtest "
End With
End If

gbMakeConnection = True

Return gCONN

End Function

Public Function GetUsers() As DataTable

Dim connection As SqlConnection = MakeConnection()
Dim da As New SqlDataAdapter("SELECT * FROM USERS", gCONN)
If gbMakeConnection Then
gCONN.Open()
da.Fill(rsUsers)
If connection.State <> ConnectionState.Closed Then
connection.Close()
Return rsUsers
End If

End Function
Jul 21 '05 #1
4 3911
follow the heirarchy, dataset has tables, tables.count.
tables has rows. rows.count ...........

"dkalsow" wrote:
Ok, I have the following code. Does any one know how I go about taking this
record set and trying to find if a record exits in it? - Thanks Dale

Imports System.Data.SqlClient

Public Module modLoadDefaults

Public gCONN As New SqlConnection
Public gbMakeConnection As Boolean
Public rsUsers As New Data.DataTable("Users")

Private Function MakeConnection() As SqlConnection

If gCONN.State <> ConnectionState.Open Then
With gCONN
.ConnectionString = "Integrated Security=TRUE;Initial
Catalog=SQL_Test;Data Source=SERVER\SQLtest "
End With
End If

gbMakeConnection = True

Return gCONN

End Function

Public Function GetUsers() As DataTable

Dim connection As SqlConnection = MakeConnection()
Dim da As New SqlDataAdapter("SELECT * FROM USERS", gCONN)
If gbMakeConnection Then
gCONN.Open()
da.Fill(rsUsers)
If connection.State <> ConnectionState.Closed Then
connection.Close()
Return rsUsers
End If

End Function

Jul 21 '05 #2
So what rsUsers.DataSet.????
"s_cnot" wrote:
follow the heirarchy, dataset has tables, tables.count.
tables has rows. rows.count ...........

"dkalsow" wrote:
Ok, I have the following code. Does any one know how I go about taking this
record set and trying to find if a record exits in it? - Thanks Dale

Imports System.Data.SqlClient

Public Module modLoadDefaults

Public gCONN As New SqlConnection
Public gbMakeConnection As Boolean
Public rsUsers As New Data.DataTable("Users")

Private Function MakeConnection() As SqlConnection

If gCONN.State <> ConnectionState.Open Then
With gCONN
.ConnectionString = "Integrated Security=TRUE;Initial
Catalog=SQL_Test;Data Source=SERVER\SQLtest "
End With
End If

gbMakeConnection = True

Return gCONN

End Function

Public Function GetUsers() As DataTable

Dim connection As SqlConnection = MakeConnection()
Dim da As New SqlDataAdapter("SELECT * FROM USERS", gCONN)
If gbMakeConnection Then
gCONN.Open()
da.Fill(rsUsers)
If connection.State <> ConnectionState.Closed Then
connection.Close()
Return rsUsers
End If

End Function

Jul 21 '05 #3
On Mon, 27 Sep 2004 12:53:03 -0700, dkalsow wrote:
So what rsUsers.DataSet.????

Public rsUsers As New Data.DataTable("Users")


In your code, rsUsers is a DataTable. Did you look at the member functions
of the DataTable class in the documentation? If you had, you would have
seen the Select method which returns an array of DataRows based on criteria
that you specify.

So you could use code similar to this:

Dim strExpression As String = "id > 6" 'Or whatever criteria you need
Dim strSort As String = "name DESC" 'Or whatever sort order you need

'This creates an array of rows that meet the expression "id > 6"
Dim selectedRows as DataRow() = rsUsers.Select(strExpression, strSort)

'This selects ALL rows
Dim allRows As DataRow() = rsUsers.Select()
Check out the docs on DataSet, DataTable, and DataRow. There is a lot of
useful information there.
--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Jul 21 '05 #4
I second that you can also create a dataview for this table and set the row
filter to the expression.

"Chris Dunaway" <"dunawayc[[at]_lunchmeat" wrote:
On Mon, 27 Sep 2004 12:53:03 -0700, dkalsow wrote:
So what rsUsers.DataSet.????

Public rsUsers As New Data.DataTable("Users")


In your code, rsUsers is a DataTable. Did you look at the member functions
of the DataTable class in the documentation? If you had, you would have
seen the Select method which returns an array of DataRows based on criteria
that you specify.

So you could use code similar to this:

Dim strExpression As String = "id > 6" 'Or whatever criteria you need
Dim strSort As String = "name DESC" 'Or whatever sort order you need

'This creates an array of rows that meet the expression "id > 6"
Dim selectedRows as DataRow() = rsUsers.Select(strExpression, strSort)

'This selects ALL rows
Dim allRows As DataRow() = rsUsers.Select()
Check out the docs on DataSet, DataTable, and DataRow. There is a lot of
useful information there.
--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: JIMMIE WHITAKER | last post by:
Can someone help on this: I am just learning, and I'm connecting to the the northwindcs.mdf tables / open file is northwindcs.adp. This is the sample installed using msde, which is supposed to be...
10
by: Andrei Ivanov | last post by:
Hello, it seems my postgresql data has somehow become corrupted (by a forced shutdown I think): psql template1 -U shadow Password: ERROR: nodeRead: did not find '}' at end of plan node...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
3
by: Randy | last post by:
I have been able to set up a Find Record Button on my switchboard to take me to a form with the correct case number by using a parameter query and macro. When I try to run the Find Record button...
1
by: Jim Heavey | last post by:
Hello, I am running into something strange. I am getting the following error when the program attempts to execute a particular procedure: An unhandled exception of type...
4
by: Aaron Smith | last post by:
Dim dv As DataView = New DataView(FacilitiesDS1.Facilities, "", "ID ASC", DataViewRowState.CurrentRows) Dim iPos As Integer = dv.Find(dr.Item("ID")) Me.BindingContext(FacilitiesDS1,...
3
by: sean | last post by:
I have a table with fixed row of records SORTED by DATE using ADO pagination method. The user can click a link in one table cell and go to another page to modify the record. Once the updated record...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
1
by: farhan31 | last post by:
Hello all I have Two tables.Table 1 and table 2.Table 1 has one to many relation with Table 2.I have one main form Form1 based on table 1.On form 1 i have a sub form based on table 2.I have put a...
1
Run2Eat
by: Run2Eat | last post by:
i feel like this is a doofus question... but i've created an access form and added a find record button, but when i use the form, the find record button searches the form itself, not the table. all...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.