using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DisplayRecordTextboxNavigate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection c = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=Test;Integrated Security=True");
SqlDataAdapter da;
DataSet ds;
int R;
private void Form1_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter("Select * From Car", c);
ds = new DataSet();
da.Fill(ds, "Car");
Getdata();
}
private void Getdata()
{
txtId.Text = ds.Tables[0].Rows[R][0].ToString();
txtCarname.Text = ds.Tables[0].Rows[R][1].ToString();
txtcarspeed.Text = ds.Tables[0].Rows[R][2].ToString();
lblrecordstatus.Text = (R + 1) + " OF " + ds.Tables[0].Rows.Count;
}
private void btnFirst_Click(object sender, EventArgs e)
{
R = 0;
Getdata();
}
private void btnNext_Click(object sender, EventArgs e)
{
if (R == ds.Tables[0].Rows.Count - 1)
{
MessageBox.Show("This is last Record");
}
else
{
R = R + 1;
Getdata();
}
}
private void btnPrev_Click(object sender, EventArgs e)
{
if (R == 0)
{
MessageBox.Show("This is first record");
}
else
{
R = R - 1;
Getdata();
}
}
private void btnLast_Click(object sender, EventArgs e)
{
R = ds.Tables[0].Rows.Count - 1;
Getdata();
}
private void btnGoto_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(txtsearchrecord.Text) < 1 || Convert.ToInt32(txtsearchrecord.Text) > ds.Tables[0].Rows.Count)
{
MessageBox.Show("Invalid Id");
}
else
{
R = Convert.ToInt32(txtsearchrecord.Text) - 1;
Getdata();
}
}
}