Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Im learning to use eof looping through recordset with no luck

Status
Not open for further replies.

mxo

Programmer
May 20, 2005
51
0
0
ZA
Hi all

i have created a dataset using the wizard and now i trying to loop through using eof and im getting an error. please see my code below:

Private Sub btnFix_Click
Dim conn As New ADODB.Connection()
Dim rec As New ADODB.Recordset()

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\line.mdb;User id=admin;Password=;"

conn.Open()

rec.Open("SELECT * FROM InvalidTable", conn, ADODB.CursorTypeEnum.adOpenDynamic)

While Not rec.EOF
If txtMSISDN.Text = txtEPX_MSISDN.Text Then
txtComment.Text = txtEPX_ACCOUNT.Text
End If

End While
 
Rather than using a while not eof

why not a FOR EACH IN REC_SET
with an Exit for when you reach then one you need.

-The answer to your problem may not be the answer to your question.
 
From the loks of your code, this is MS Access (VBA). This is the forum for that: forum705

I agree with Qik3Coder, you should exit the loop when you find what you need. However, don't you want to be comparing something in your recordset to one of the text boxes?

You also need a rec.MoveNext in your while loop, or else you will never get to EOF.

Hope this helps,

Alex


Ignorance of certain subjects is a great part of wisdom
 
AlexCuse, i didnt delve into his actual code, but that would make sense for why he never got a eof.
I disagree with the move to VBA comment though. If he is manipulating the MSAccess database with .NET, then it is a valid .Net question.


MXO, one thing to keep in mind, when you are working with a WHILE loop you are responsible for handing your "EXITING" clause. And Alex is right agout the move next, if you are using a While loop, but the for loop "should" take care of that for you.

-The answer to your problem may not be the answer to your question.
 
Qik3Coder, I did not mean move to VBA. I meant it is VBA code (or VB6). WOuldn't a VB.net sub be followed with something like this:

Code:
(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

mxo - what are you writing this in? MS Access, Visual Studio/Basic 6, or Visual Studio/Basic .net?

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Hi Alexcuse & Qik3Coder im writing this on vb.net so is my code in not suitable for vb.net or using eof wont work on vb.net and for vb.net what would be correct way of writing this code.

sorry for being bit slow was trying to see if its possible.
 
You don't say exactly what your problem is, just
mxo said:
Im learning to use eof looping through recordset with no luck

Two things comne to mind, one Alex is right about your [tt]Private Sub btnFix_Click[/tt] declaration, and two, if you posted your complete code for the [tt]while[/tt] loop, you will never reach .EOF unless you are there on entry to the loop. You need to move to the next record BEFORE [tt]End While[/tt]


Hope this helps.

[vampire][bat]
 
What does the error say?
And maybe you need a MoveNext statement:
Code:
While Not rec.EOF
            If txtMSISDN.Text = txtEPX_MSISDN.Text Then
                txtComment.Text = txtEPX_ACCOUNT.Text
            End If
            [blue]rec.MoveNext[/blue]
        End While

Hope this helps.
 
ADODB is completely outdated.

try using ado.net

like earthandfire says, your method isn't in any usual vb.net format (no handles).

There are plenty of examples on google about ado.net and ms access.

Christiaan Baes
Belgium

"My old site" - Me
 
mxo, what they are getting at is that your code should probably look something like:


Code:
Dim dtInfo As New DataTable()
Dim cn As SqlConnection(ConfigurationManager.ConnectionStrings("myConn").ConnectionString)
Dim cmdGetInfo As New SqlCommand()
cmdGetinfo.CommandType = CommandType.StoredProcedure
cmdGetInfo.CommandText = "dbo.getStuff"
cmdGetInfo.Parameters.Add("@param1", SqlDbType.Char).Value = strmyParam
Try
            cn.Open()
            Dim daGet As New SqlDataAdapter(cmdSql)
            ' Populate a new data table and bind it to the BindingSource.
            Dim dtGet As New DataTable()
            dtGet.Locale = System.Globalization.CultureInfo.InvariantCulture
            daGet.Fill(dtGet)
Catch ex As Exception
            cn.Close()
Finally
            cn.Close()
End Try
dtInfo = dtGet
Return dtInfo

-The answer to your problem may not be the answer to your question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top