C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Visual Studio »

Code for next,previous,first,last records...


Posted Date: 17 Jun 2008    Resource Type: Code Snippets    Category: Visual Studio
Author: antogladwinMember Level: Silver    
Rating: 1 out of 5Points: 10



This code is for to get the first,last,previous,next records.....
==================================================================
If we want to see the next,previous,first,last means we will use code like ,

int n=0;//global declaration
datatable dt;
form_load()
{
con...............
................//connection whatever you want...
sqldataadapter da=new sqldataadapter("select * from ",con);
dataset ds=new dataset();
da.fill(ds,"ali");//ali is ur table name or whatever your table
dt=ds.tables["ali"];
display();
}

first_click() //first record button(<<)
{
n=0;
display();
}
previous_click() //previous record button(<)
{
n=n-1;
if(n==-1)
{
n=0;
messagebox.show("first record);
}
else
{
display();
}
}
next_click() //next record button(>)
{
n=n+1
if(n>dt.rows.count-1)
}
else
{
display();
}
}
last_click() //last record button(>>)
{
n=dt.rows.count-1;
display();
}

display() //display function
{
datarow dr=dt.rows[n];
textbox1.text=dr[0].tostring();
textbox2.text=dr[1].tostring();
}


Happy Coding,
BY,
R.A.Gladwin



Responses

Author: javier    09 Dec 2008Member Level: Bronze   Points : 2
the code has a few errors, like "int n=o;" on the first line, which is an easy fix, just replace the letter "o" with the number "0".

But in the last few lines it refers to "dr" textbox2.text=dr[1].tostring();

dr is not declared anywhere within the code.

I'd like to see this fix as I'm looking forward to understand how the whole thing works and I haven't been able to find a lot of information about this specific topic.


Author: antogladwin    10 Dec 2008Member Level: Silver   Points : 1
hi javier,

i updated the code..thank you for your valuable comments..


by,
R.A.Gladwin


Author: antogladwin    10 Dec 2008Member Level: Silver   Points : 1
hi javier,

if you can't understand hereafter also means...im ready to explain, friend.thank you..

//FYI(For your information)

* display() is a function..

* first,last....are buttons

by,
R.A.Gladwin


Author: Sachin    02 Jul 2009Member Level: Gold   Points : 0
Its very use full article..Thanks a lot


Author: Anilkumar    24 Aug 2009Member Level: Bronze   Points : 2
When am using this code display error like this
Class, struct, or interface method must have a return type

I wrote the code like
public partial class RegisterPatient : Form
{
int n = 0;
datatable dt;
public RegisterPatient()
{
InitializeComponent();
}

private void RegisterPatient_Load(object sender, EventArgs e)
{
SqlConnection Con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=HMS1;Data Source=ALIGNSOFT9\\SQLEXPRESS");
Con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from RegisterAdmitPatient_details", Con);
DataSet ds = new DataSet();
da.Fill(ds,"RegisterAdmitPatient_details");
dt=ds.tables["RegisterAdmitPatient_details"];
display ();
}


private void btnfirst_Click(object sender, EventArgs e)
{
n = 0;
display();
}

private void btnprevious_Click(object sender, EventArgs e)
{
n=n-1;
if(n==-1)
{
n=0;
messagebox.show("first record");
}
else
{
display();
}
}

private void btnNext_Click(object sender, EventArgs e)
{
n = n + 1;
if(n>dt.rows.count-1)
{
}
else
{
display();
}
}

private void btnlast_Click(object sender, EventArgs e)
{
n = dt.rows.count - 1;
display();
}
display() //display function
{
datarow dr=dt.rows[n];
textbox1.text=dr[0].tostring();
textbox2.text=dr[1].tostring();
}
}


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Career with microsoft  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Shortcuts for Visual Studio
Previous Resource: Autogeneration numbers...
Return to Discussion Resource Index
Post New Resource
Category: Visual Studio


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use