using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Ajans
{
    public partial class Form10 : Form
    {
        String StrConn;
        String StrQury;
        public Form10()
        {
            InitializeComponent();
        }

        private void Form10_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'havapeymaDataSet3.Ajans' table. You can move, or remove it, as needed.
            this.ajansTableAdapter.Fill(this.havapeymaDataSet3.Ajans);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection myConn;
            SqlCommand myComm;
            StrConn = "SERVER=.;DATABASE=Havapeyma;Integrated Security=True";
            StrQury = "Update Ajans Set CodeA=@CodeA,NameA=@NameA ,TelA=@TelA,AddressA=@AddressA";


            myConn = new SqlConnection(StrConn);

            myComm = new SqlCommand();
            myComm.Connection = myConn;
            myComm.CommandType = CommandType.Text;
            myComm.CommandText = StrQury;
            myComm.Parameters.Add("CodeA", SqlDbType.NVarChar, 50).Value = this.CodeH.Text;
            myComm.Parameters.Add("NameA", SqlDbType.NVarChar, 50).Value = this.textBox1.Text;
            myComm.Parameters.Add("TelA", SqlDbType.NVarChar, 50).Value = this.textBox2.Text;
            myComm.Parameters.Add("AddressA", SqlDbType.NVarChar, 50).Value = this.textBox3.Text;

            myConn.Open();
            myComm.ExecuteNonQuery();
            myConn.Close();
            show1();
            CodeH.Text = ""; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = "";
            CodeH.Focus();


        }

        private void show1()
        {
            SqlDataAdapter myDA;
            DataSet myDS;

            StrConn = "SERVER=.;DATABASE=Havapeyma;Integrated Security=True";
            StrQury = "Select * From Ajans";
            myDA = new SqlDataAdapter(StrQury, StrConn);

            myDS = new DataSet();

            myDA.Fill(myDS, "Ajans");

            this.dataGridView1.DataSource = myDS;
            this.dataGridView1.DataMember = "Ajans";
            this.dataGridView1.AutoGenerateColumns = true;
            this.dataGridView1.RightToLeft = RightToLeft.Yes;
            this.dataGridView1.Refresh();
        }
    }
}
