Hi!! How I can solve thise problem?
public partial class Form1 : Form
{
SqlConnection con = myConnection.GetConnection();
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
GetData();
}
public void GetData()
{
SqlCommand cmd = new SqlCommand("SELECT SURNAME,NAM,LASTNAME,BIRTHDAY,ADDRESS FROM INFO", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
con.Open();
sda.Fill(dt);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.Columns[0].Name = "SURNAME";
dataGridView1.Columns[0].HeaderText = " SURNAME";
dataGridView1.Columns[0].DataPropertyName = "SURNAME";
dataGridView1.Columns[1].Name = "NAM";
dataGridView1.Columns[1].HeaderText = " NAME";
dataGridView1.Columns[1].DataPropertyName = "NAM";
dataGridView1.Columns[2].Name = "LASTNAME";
dataGridView1.Columns[2].HeaderText = " LASTNAME";
dataGridView1.Columns[2].DataPropertyName = "LASTNAME";
dataGridView1.Columns[3].Name = "BIRTHDAY";
dataGridView1.Columns[3].HeaderText = " BIRTHDAY";
dataGridView1.Columns[3].DataPropertyName = "BIRTHDAY";
dataGridView1.Columns[4].Name = "ADDRESS";
dataGridView1.Columns[4].HeaderText = " ADDRESS";
dataGridView1.Columns[4].DataPropertyName = "ADDRESS";
dataGridView1.DataSource = dt;
con.Close();
}
private void Add_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "PINFO";
con.Open();
cmd.Parameters.AddWithValue("@Surname", Surname.Text.Trim());
cmd.Parameters.AddWithValue("@Nam", Nam.Text.Trim());
cmd.Parameters.AddWithValue("@Lastname", Lastname.Text.Trim());
cmd.Parameters.AddWithValue("@Birthday", Birthday.Text);
cmd.Parameters.AddWithValue("@Address", Address.Text.Trim());
try
{
cmd.ExecuteNonQuery();
con.Close();
Surname.Text = string.Empty;
Nam.Text = string.Empty;
Lastname.Text = string.Empty;
Birthday.Text = string.Empty;
Address.Text = string.Empty;
dt.Clear();
GetData();
Surname.Focus();
}
catch
{
MessageBox.Show("Error: Data not saved in database!!!");
}
}
private void Search_TextChanged(object sender, EventArgs e)
{
string cmd = "SELECT * FROM info WHERE SurName LIKE @surname + '%'";
DataTable dt = new DataTable();
using (SqlDataAdapter a = new SqlDataAdapter())
{
try
{
a.SelectCommand = new SqlCommand();
a.SelectCommand.Connection = con;
a.SelectCommand.CommandType = CommandType.Text;
a.SelectCommand.CommandText = cmd;
a.SelectCommand.Parameters.AddWithValue("@surname", Search.Text);
a.Fill(dt);
dataGridView1.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
|
Pulodov
|
Rustam
|
Abdulloevich
|
22.12.1987
|
city. Kulob
|
|
Pulodov
|
Firuz
|
Abdulloevich
|
19.04.1998
|
region Shuroobod
|
|
Pulodov
|
Bakhtiyor
|
Nurovich
|
01.01.1986
|
city Dushanbe
|
|
Pulodov
|
Firdavs
|
Firuzovich
|
09.09.1990
|
city Kulob
|
|
Pirov
|
Mirzo
|
Nurovich
|
11.11.1990
|
city. Kulob
|
|
Pirov
|
Amonullo
|
Nurulloevich
|
22.12.1987
|
region Shuroobod
|
|
|
|
|
|
|
|
Search:
|
p
|
|
|
|
When I input “P” show all word begin to letter “P” it’s goog work. But I want four button go to next, End or Back record database.
Such:
Button for First record
|
Button for End record
|
Button for Next record
|
Button for Back record
|
|
|
How I can use these button when I click Button for End record I see end record in database. If I click Button for Next record only one step go and show second record database. Please help me!!!