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

Database manipulation using DataAdapter

Hi,

I develop a code for data manipulation i.e (first, next, previous and last record). i try the below mentioned code,

In this, i click next button -- move the next record. i click one more time it doesnt move

same as for previous button.


protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
//SqlCommand cmd = new SqlCommand();
con.ConnectionString = "Data source=localhost;initial catalog=northwind;integrated security=true";

String cmd = "select * from employees";
//cmd.CommandType = CommandType.Text;
//cmd.Connection = con;
//cmd.Connection.Open();

SqlDataAdapter da = new SqlDataAdapter(cmd, con);


DataSet ds = new DataSet();
da.Fill(ds, "employeeinfo");
dt = ds.Tables["employeeinfo"];
tot = dt.Rows.Count;
Label5.Text = tot.ToString();
fill();

//SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
//Label5.Text= Convert.ToString(dr.FieldCount);
//while (dr.Read())
//{
// TextBox1.Text = dr["employeeid"].ToString();
// TextBox2.Text = dr["firstname"].ToString();
// TextBox3.Text = dr["city"].ToString();
// TextBox4.Text = dr["country"].ToString();
//}
//Label5.Text=dr.RecordsAffected.ToString();

//GridView1.DataSource = dr;
//GridView1.DataBind();

//cmd.Dispose();
//dr.Dispose();
}
protected void Button6_Click(object sender, EventArgs e)
{
//First record
cur = 0;
fill();
Label5.Text = cur.ToString();
}
protected void Prev_Click(object sender, EventArgs e)
{
//previous record
cur--;
if (cur < 0)
cur = tot - 1;
fill();
Label5.Text = cur.ToString();

}
private void fill()
{
TextBox1.Text = dt.Rows[cur]["employeeid"].ToString();
TextBox2.Text = dt.Rows[cur]["firstname"].ToString();
TextBox3.Text = dt.Rows[cur]["city"].ToString();
TextBox4.Text = dt.Rows[cur]["country"].ToString();
Label5.Text = cur.ToString();
}
protected void Button8_Click(object sender, EventArgs e)
{
if (cur < tot - 1)
{
cur = cur + 1;
fill();
}

// //Next record
// cur = cur + 1;
// if (cur > tot-1)
// {
//// cur = 0;
// }
// else
// {
// fill();
// }

// Label5.Text = cur.ToString();
}
protected void Button9_Click(object sender, EventArgs e)
{
//Last record
cur = tot - 1;
fill();
Label5.Text = cur.ToString();
}

thanks,
murugavel
Jul 10 '08 #1
0 744

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
0
by: Pietje puk | last post by:
Hello, Since im quite new to ASP.NET i wanted to ask you folks what the best way is to create a WebForm for modifying 1 field from a record. The manipulation of this field can be done by using...
3
by: Solution Seeker | last post by:
I want to Store the String value with Single Quotes in the Field of Database where if i try to Store the String value with Single Quotes (as it is) then it is throwing the error as SQL String...
1
by: Rico | last post by:
I have tried to access a database using asp.net. after some entries like 120+, I got an unspecified error message. Anyone know what is happening, it seems to be stuck at the same line even when i...
1
by: saywhat | last post by:
Okay, please forgive me but I need to ask this... I went to Google and pressed the button etc. first, really, before I asked... lol I'm familiar with database manipulation in C++/MFC. I noticed...
16
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataAdapter. For every record in tblA where colB = 'abc', I want to update the value in colA. In VB6, using ADO I can loop thru the recordset,set the...
0
by: gyap88 | last post by:
I'm using VB 2005 to create a simple application where authorised users can edit the database. Firstly, the database will be imported into a datatable and into a datagrid. Public Class...
9
by: Peter Duniho | last post by:
Is there a straightfoward API in .NET that allows for inspection of a database? That is, to look at the structure of the database, without knowing anything in advance about it? For example,...
0
MrMancunian
by: MrMancunian | last post by:
How to create a database connection without using wizards Introduction I've seen a lot of questions on the net about getting data from, and saving data to databases. Here's a little insight how...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.