473,387 Members | 1,891 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,387 software developers and data experts.

ADO Record Set rs.MoveNext(); problem....help please

Ok,
Everything connects correctly and loads properly in this
WebApplication. I have four buttons and all work correctly except one
(the NEXT RECORD button). PREVIOUS, FIRST and LAST all work properly.
This identical code works correctly in a windows app.
Please tell me what I am doing wrong.

Here is my connection code:

private void InitializeDataConnection ()
{

// frmStatus frmStatusMessage = new frmStatus();
if (!HasConnected)
{
// frmStatusMessage.Show("Connecting to SQL Server");

// Attempt to connect to SQL server or MSDE
bool IsConnecting = true;

while (IsConnecting)
{
try
{
// Open a Connection
cnn.ConnectionTimeout = 0;
cnn.CommandTimeout = 0;
cnn.Open(Connectionstring, null,null,0);

if (cnn.State != 1)
{
throw new System.Exception("Connection failed.");
}
if (!HasConnected)
{
// frmStatusMessage.Close();
}
IsConnecting = false;
HasConnected = true;
}
catch
{
if (Connectionstring == SQL_CONNECTION_STRING)
{
// Couldn't connect to SQL server. Now try MSDE
// Connectionstring = MSDE_CONNECTION_STRING;
// frmStatusMessage.Show("Connecting to MSDE");
}
else
{
// Unable to connect to SQL Server or MSDE
// frmStatusMessage.Close();

// MessageBox.Show("To run this sample you must have SQL
Server ot MSDE with the Northwind database installed. For instructions
on installing MSDE, view the Readme file." + MessageBoxIcon.Warning +
"SQL Server/MSDE not found");
// Quit program if neither connection method was successful.
// Application.Exit();
}
}
}
}
// }

// Build SQL statement.
// string strSQL = "SELECT * " +
// "FROM member " ;

string strSQL = "SELECT t1.member_id, t1.first_name, t1.last_name "
+
"FROM member t1 " ;

rs.ActiveConnection = cnn;
rs.CursorType = CursorTypeEnum.adOpenStatic;
rs.Open(strSQL,cnn,ADODB.CursorTypeEnum.adOpenDyna mic,ADODB.LockTypeEnum.adLockOptimistic,0);
rs.MoveFirst();

}

and here is the code giving the problem:

private void Button2_Click(object sender, System.EventArgs e)
{
// this code is used to prevent going to EOF
if (!rs.EOF)
{
rs.MoveNext();
if (rs.EOF)
{
rs.MovePrevious();
}
PopulateSimpleNavigationForm();
}
}

Any help is appreciated.
Thanks,
Trint

Nov 17 '05 #1
5 4584
Why are you using ADO in a .NET application?

"trint" <tr***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Ok,
Everything connects correctly and loads properly in this
WebApplication. I have four buttons and all work correctly except one
(the NEXT RECORD button). PREVIOUS, FIRST and LAST all work properly.
This identical code works correctly in a windows app.
Please tell me what I am doing wrong.

Here is my connection code:

private void InitializeDataConnection ()
{

// frmStatus frmStatusMessage = new frmStatus();
if (!HasConnected)
{
// frmStatusMessage.Show("Connecting to SQL Server");

// Attempt to connect to SQL server or MSDE
bool IsConnecting = true;

while (IsConnecting)
{
try
{
// Open a Connection
cnn.ConnectionTimeout = 0;
cnn.CommandTimeout = 0;
cnn.Open(Connectionstring, null,null,0);

if (cnn.State != 1)
{
throw new System.Exception("Connection failed.");
}
if (!HasConnected)
{
// frmStatusMessage.Close();
}
IsConnecting = false;
HasConnected = true;
}
catch
{
if (Connectionstring == SQL_CONNECTION_STRING)
{
// Couldn't connect to SQL server. Now try MSDE
// Connectionstring = MSDE_CONNECTION_STRING;
// frmStatusMessage.Show("Connecting to MSDE");
}
else
{
// Unable to connect to SQL Server or MSDE
// frmStatusMessage.Close();

// MessageBox.Show("To run this sample you must have SQL
Server ot MSDE with the Northwind database installed. For instructions
on installing MSDE, view the Readme file." + MessageBoxIcon.Warning +
"SQL Server/MSDE not found");
// Quit program if neither connection method was successful.
// Application.Exit();
}
}
}
}
// }

// Build SQL statement.
// string strSQL = "SELECT * " +
// "FROM member " ;

string strSQL = "SELECT t1.member_id, t1.first_name, t1.last_name "
+
"FROM member t1 " ;

rs.ActiveConnection = cnn;
rs.CursorType = CursorTypeEnum.adOpenStatic;
rs.Open(strSQL,cnn,ADODB.CursorTypeEnum.adOpenDyna mic,ADODB.LockTypeEnum.adLockOptimistic,0);
rs.MoveFirst();

}

and here is the code giving the problem:

private void Button2_Click(object sender, System.EventArgs e)
{
// this code is used to prevent going to EOF
if (!rs.EOF)
{
rs.MoveNext();
if (rs.EOF)
{
rs.MovePrevious();
}
PopulateSimpleNavigationForm();
}
}

Any help is appreciated.
Thanks,
Trint

Nov 17 '05 #2
Trint,

I would replace that section with a check to the RecordCount property.
If the property is = 1 (meaning one record), then do nothing, otherwise,
call MoveNext.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"trint" <tr***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Ok,
Everything connects correctly and loads properly in this
WebApplication. I have four buttons and all work correctly except one
(the NEXT RECORD button). PREVIOUS, FIRST and LAST all work properly.
This identical code works correctly in a windows app.
Please tell me what I am doing wrong.

Here is my connection code:

private void InitializeDataConnection ()
{

// frmStatus frmStatusMessage = new frmStatus();
if (!HasConnected)
{
// frmStatusMessage.Show("Connecting to SQL Server");

// Attempt to connect to SQL server or MSDE
bool IsConnecting = true;

while (IsConnecting)
{
try
{
// Open a Connection
cnn.ConnectionTimeout = 0;
cnn.CommandTimeout = 0;
cnn.Open(Connectionstring, null,null,0);

if (cnn.State != 1)
{
throw new System.Exception("Connection failed.");
}
if (!HasConnected)
{
// frmStatusMessage.Close();
}
IsConnecting = false;
HasConnected = true;
}
catch
{
if (Connectionstring == SQL_CONNECTION_STRING)
{
// Couldn't connect to SQL server. Now try MSDE
// Connectionstring = MSDE_CONNECTION_STRING;
// frmStatusMessage.Show("Connecting to MSDE");
}
else
{
// Unable to connect to SQL Server or MSDE
// frmStatusMessage.Close();

// MessageBox.Show("To run this sample you must have SQL
Server ot MSDE with the Northwind database installed. For instructions
on installing MSDE, view the Readme file." + MessageBoxIcon.Warning +
"SQL Server/MSDE not found");
// Quit program if neither connection method was successful.
// Application.Exit();
}
}
}
}
// }

// Build SQL statement.
// string strSQL = "SELECT * " +
// "FROM member " ;

string strSQL = "SELECT t1.member_id, t1.first_name, t1.last_name "
+
"FROM member t1 " ;

rs.ActiveConnection = cnn;
rs.CursorType = CursorTypeEnum.adOpenStatic;
rs.Open(strSQL,cnn,ADODB.CursorTypeEnum.adOpenDyna mic,ADODB.LockTypeEnum.adLockOptimistic,0);
rs.MoveFirst();

}

and here is the code giving the problem:

private void Button2_Click(object sender, System.EventArgs e)
{
// this code is used to prevent going to EOF
if (!rs.EOF)
{
rs.MoveNext();
if (rs.EOF)
{
rs.MovePrevious();
}
PopulateSimpleNavigationForm();
}
}

Any help is appreciated.
Thanks,
Trint

Nov 17 '05 #3
Nicholas,

ErrorLabel.Text = (rs.RecordCount.ToString()); is always -1
Does that mean that it's no longer open? But it moves with LAST
FIRST Previous?
I don't understand.
Thanks,
Trint

Nov 17 '05 #4
Trint,

It's odd, you set the CursorType as static, then you open it with
dynamic. Unless you need to see changes that occur in the data as it
happens, I would change it to static. Because it is dynamic, I believe that
the recordset waits until you get to the end to calculate the record count.

I think that the cursor location has something to do with it as well. I
believe that if the cursor location is server, then the record count
property is affected as well.

All if this makes me very happy that there is one model for data access
in .NET (disconnected client side cursors).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"trint" <tr***********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Nicholas,

ErrorLabel.Text = (rs.RecordCount.ToString()); is always -1
Does that mean that it's no longer open? But it moves with LAST
FIRST Previous?
I don't understand.
Thanks,
Trint

Nov 17 '05 #5
Nick,
I tried changing to "adOpenStatic" and it didn't change its
behavior...but, I think you are on to something
with what is wrong.
Thanks,
Trint

Nov 17 '05 #6

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

Similar topics

8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
1
by: David | last post by:
Hi, I have a continuous form based on a query. Lets say the form displays 6 records. I also have a button against each record which sets a field to Y or N for each record. I am trying to...
20
by: MS | last post by:
Access 97 I want to requery the data being displayed on a form, then I want to return to the record I was in. Why doesn't this code work? Private Sub CmdRefsh_Click()
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
3
by: trint | last post by:
Ok, MoveNext is only moving to the next record once, then it stays on that record unless I use these (which work just fine) MoveLast MoveFirst MovePrevious. private void btnNext_Click(object...
1
by: Trevor Fairchild | last post by:
Hello all - I've been working in VB6 for about a year and now I've moved "up" to VB.NET. I think I would have fewer problems in learning vb.net if I knew nothing about previous versions of vb......
19
by: Genalube | last post by:
I have an application that will produce a Word document based on five separate queries this has required that I create a ADODB connection: 'Create connection to current database Dim Conn As...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
3
by: Kosmos | last post by:
Hey ya'll...I can't seem to figure out why I'm getting this error message, but it all started when I added the new line of code with the recSet5.AddNew --- when I ran the first line, the logic worked...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.