Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection conn = null;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                try
                {
                    string Name = row.Cells[1].Value.ToString();
                    string DOB = row.Cells[2].Value.ToString();
                    string GradePointAvg = row.Cells[3].Value.ToString();
                    string Active = row.Cells[4].Value.ToString();

                    if (Active.Equals("false"))
                    {
                        Dbconnection dbconnect = new Dbconnection();
                        dbconnect.Registration(Name, DOB, GradePointAvg, Active);
                        MessageBox.Show("inserted sussfully");

                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
        private void savedata_Click(object sender, EventArgs e)
        {
            db = new Dbconnection();


            if (txtname.TextLength == 0 || txtpassword.TextLength == 0 || txtid.TextLength == 0)
            {
                MessageBox.Show("null values ara not allowd");
            }
            else
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("insert into login values('" + txtname.Text + "','" + txtpassword.Text + "'," + txtid.Text + ")", db.con);
                    db.con.Open();
                    //String name = Convert.ToString(cmd.ExecuteScalar());
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("inserted");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex.Message);
                }
                finally
                {
                    db.con.Close();
                }
            }
        }
Esempio n. 3
0
 public void loadtable()
 {
     Dbconnection dbconnect = new Dbconnection();
     tablegrid = dbconnect.getAllStudents();
     if (tablegrid != null)
     {
         dataGridView1.DataSource = tablegrid.DefaultView;
     }
 }
        public void insertdata()
        {
            db = new Dbconnection();
            SqlCommand cmd = new SqlCommand("insert into login values('" + name + "','" + password + "'," + id + ")", db.con);

            db.con.Open();
            cmd.ExecuteNonQuery();
            MessageBox.Show("inserted");
        }
        private void update_Click(object sender, EventArgs e)
        {
            db = new Dbconnection();
            SqlCommand cmd = new SqlCommand("update login set userName='******',password='******'  where userid = '" + txtid.Text + "'  ", db.con);

            db.con.Open();
            cmd.ExecuteNonQuery();
            MessageBox.Show("updated");
            db.con.Close();
        }
        private void btndelete_Click(object sender, EventArgs e)
        {
            db = new Dbconnection();
            SqlCommand cmd = new SqlCommand("delete from login where userid = '" + txtid.Text + "'  ", db.con);

            db.con.Open();
            cmd.ExecuteNonQuery();
            MessageBox.Show("deleted");
            db.con.Close();
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            db = new Dbconnection();
            SqlDataAdapter adp = new SqlDataAdapter("select * from login where userid = '" + txtid.Text + "'  ", db.con);

            db.con.Open();
            DataTable dt = new DataTable();

            adp.Fill(dt);
            dataGridView1.DataSource = dt;
            db.con.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            db = new Dbconnection();
            SqlDataAdapter adp = new SqlDataAdapter("select * from login", db.con);

            db.con.Open();
            DataTable dt = new DataTable();

            adp.Fill(dt);
            dataGridView1.DataSource = dt;
            db.con.Close();
        }