private void loadData() { //count++; //welcome well = new welcome(); //well.ShowDialog(); //user = well.return_user().ToString().ToUpper(); //this.Text = "Digital Phone Directory" + " (" + " " + user + " " + ")"; //MessageBox.Show(well.isSucs().ToString() + " " + well.return_user().ToString()); using (SqlConnection conn = new SqlConnection(@"Data Source=" + COMPUTER_NAME.ToString().ToUpper() + ";Initial Catalog=PhoneDirectory;Integrated Security=true")) { using (SqlDataAdapter adapter = new SqlDataAdapter( "SELECT Name,Nickname,PhoneNumber,MobileNumber,EmailAddress,HomeAddress,Company,Position,GroupName,Website,FacebookAccount FROM DETAILS_ABOUT_USERS WHERE Remarks = '' AND FK_USERNAME = '******'", conn)) { try { DataSet ds = new DataSet(); adapter.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; }catch (SqlException _) { DialogResult result = MessageBox.Show("ensure the database is up and running!\n" + _.Message.ToString(), "warning", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Information); if (result == System.Windows.Forms.DialogResult.Abort) { Application.Exit(); } else if (result == System.Windows.Forms.DialogResult.Retry) { /**/ // let the sqlconnection object create the database } else if (result == System.Windows.Forms.DialogResult.Cancel) { Application.Exit(); } } } } }
private void loadData(string searcher, string field) { name = searcher; if (comboBox1.Text == "") { try { using (SqlConnection conn = new SqlConnection( @"Data Source=" + COMPUTER_NAME.ToString().ToUpper() + ";Initial Catalog=PhoneDirectory;Integrated Security=true")) { using (SqlDataAdapter adapter = new SqlDataAdapter( "SELECT Name,Nickname,PhoneNumber,MobileNumber,EmailAddress,HomeAddress,Company,Position,GroupName,Website,FacebookAccount FROM DETAILS_ABOUT_USERS WHERE FK_USERNAME = '******' AND ( Name LIKE '%" + name + "%' or Nickname LIKE '%" + name + "%' or PhoneNumber LIKE '%" + name + "%' or MobileNumber LIKE '%" + name + "%' or EmailAddress LIKE '%" + name + "%' or HomeAddress LIKE '%" + name + "%' or Company LIKE '%" + name + "%' or Position LIKE '%" + name + "%' or GroupName LIKE '%" + name + "%' or Website LIKE '%" + name + "%' or FacebookAccount LIKE '%" + name + "%' )", conn)) { DataSet ds = new DataSet(); adapter.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } } } catch (Exception er) { } } else { try { using (SqlConnection conn = new SqlConnection( @"Data Source=" + COMPUTER_NAME.ToString().ToUpper() + ";Initial Catalog=PhoneDirectory;Integrated Security=true")) { using (SqlDataAdapter adapter = new SqlDataAdapter( "SELECT Name,Nickname,PhoneNumber,MobileNumber,EmailAddress,HomeAddress,Company,Position,GroupName,Website,FacebookAccount FROM DETAILS_ABOUT_USERS WHERE " + " FK_USERNAME = '******' AND ( " + field + " LIKE '%" + textBox1.Text + "%' )", conn)) { DataSet ds = new DataSet(); adapter.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } } } catch (Exception er) { } } }