با سلام مجدد
کد فرم مورد نظر رو می زارم شاید به دردتون بخوره
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 kala
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
String connect = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\kdbs.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlDataAdapter da;
DataSet ds;
int i = 0;
SqlConnection conn;
private void Form3_Load(object sender, EventArgs e)
{
conn = new SqlConnection(connect);
conn.Open();
da = new SqlDataAdapter("select cost_id,cost_name from moshtari", conn);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "moshtari");
textBox2.Text = ds.Tables[0].Rows[i]["cost_id"].ToString();
textBox3.Text = ds.Tables[0].Rows[i]["cost_name"].ToString();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (ds.Tables[0].Rows.Count > 0)
{
i = 0;
textBox2.Text = ds.Tables[0].Rows[i]["cost_id"].ToString();
textBox3.Text = ds.Tables[0].Rows[i]["cost_name"].ToString();
}
}
private void button4_Click(object sender, EventArgs e)
{
i = ds.Tables[0].Rows.Count - 1;
textBox2.Text = ds.Tables[0].Rows[i]["cost_id"].ToString();
textBox3.Text = ds.Tables[0].Rows[i]["cost_name"].ToString();
}
private void button2_Click(object sender, EventArgs e)
{
if (i < ds.Tables[0].Rows.Count - 1)
{
i++;
textBox2.Text = ds.Tables[0].Rows[i]["cost_id"].ToString();
textBox3.Text = ds.Tables[0].Rows[i]["cost_name"].ToString();
}
else
{
}
}
private void button3_Click(object sender, EventArgs e)
{
if (i == ds.Tables[0].Rows.Count - 1 || i != 0)
{
i--;
textBox2.Text = ds.Tables[0].Rows[i]["cost_id"].ToString();
textBox3.Text = ds.Tables[0].Rows[i]["cost_name"].ToString();
}
else
{
}
}
}
}