private void bttSearch_Click(object sender, EventArgs e) { string query = "select distinct std.id, std.fname, std.lname from std inner join score on std.id=score.student_id where concat(std.id,std.fname) like '%" + txtSearch.Text + "%'"; SqlCommand command = new SqlCommand(query, mydb.getConnection); mydb.openConnection(); SqlDataReader reader = command.ExecuteReader(); int i = 3; while (reader.Read()) { dataGridView1.Rows[0].Cells[0].Value = reader.GetString(0); dataGridView1.Rows[0].Cells[1].Value = reader.GetString(1); dataGridView1.Rows[0].Cells[2].Value = reader.GetString(2); } mydb.closeConnection(); goidiem(); mydb.closeConnection(); dataGridView1.Rows[0].Cells[7].Value = avg(); mydb.closeConnection(); if (avg() < 5) { dataGridView1.Rows[0].Cells[8].Value = "Fail"; } else { dataGridView1.Rows[0].Cells[8].Value = "Pass"; } mydb.closeConnection(); }
public bool insertContact(int id, string fname, string lname, string phone, string address, string email, int userid, int groupid, MemoryStream picture) { SqlCommand cm = new SqlCommand("insert into mycontact (id , fname , lname , group_id , phone , address , pic , userid , email ) values (@id, @fn, @ln, @grp, @phn, @adrs, @pic, @uid, @mail)", con.getConnection); cm.Parameters.Add("@id", SqlDbType.Int).Value = id; cm.Parameters.Add("@fn", SqlDbType.VarChar).Value = fname; cm.Parameters.Add("@ln", SqlDbType.VarChar).Value = lname; cm.Parameters.Add("@grp", SqlDbType.NChar).Value = groupid; cm.Parameters.Add("@phn", SqlDbType.NChar).Value = phone; cm.Parameters.Add("@mail", SqlDbType.NChar).Value = email; cm.Parameters.Add("@adrs", SqlDbType.Text).Value = address; cm.Parameters.Add("@uid", SqlDbType.Int).Value = userid; cm.Parameters.Add("@pic", SqlDbType.Image).Value = picture.ToArray(); con.openConnection(); if (cm.ExecuteNonQuery() == 1) { con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } }
public bool insertUser(int id, string fname, string lname, string username, string password, MemoryStream picture) { SqlCommand cmd = new SqlCommand("INSERT INTO hr (id, f_name, l_name, uname, pwd, fig) VALUES (@id , @fn, @ln, @un, @pass, @pic)", con1.getConnection); //SqlCommand cmd = new SqlCommand("INSERT INTO hr id=@id, f_name=@fn, l_name=@ln, uname=@un, pwd=@pass, fig=@pic ", con.connection); cmd.Parameters.Add("@id", SqlDbType.Int).Value = id; cmd.Parameters.Add("@fn", SqlDbType.VarChar).Value = fname; cmd.Parameters.Add("@ln", SqlDbType.VarChar).Value = lname; cmd.Parameters.Add("@un", SqlDbType.VarChar).Value = username; cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = password; cmd.Parameters.Add("@pic", SqlDbType.Image).Value = picture.ToArray(); con1.openConnection(); if (cmd.ExecuteNonQuery() == 1) { con1.closeConnection(); return(true); } else { con1.closeConnection(); return(false); } }
public bool insertGroup(int id, string gname, int userid) { SqlCommand cm = new SqlCommand("insert into mygroups (id, name, userid) values (@id, @gr, @uid)", db.getConnection); cm.Parameters.Add("@id", SqlDbType.Int).Value = id; cm.Parameters.Add("@gr", SqlDbType.VarChar).Value = gname; cm.Parameters.Add("@uid", SqlDbType.Int).Value = userid; db.openConnection(); if (cm.ExecuteNonQuery() == 1) { db.closeConnection(); return(true); } else { db.closeConnection(); return(false); } }