Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
- SqlCommand command = new SqlCommand("Select * FROM address_book ", connection);
- try
- {
- connection.Open();
- {
- SqlDataReader drd = command.ExecuteReader();
- while (drd.Read())
- {
- this.checkedListBox1.Items.Add(drd.GetString(0).ToString());
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- }
- connection.Close();
- }
- private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
- con.Open();
- SqlCommand cmd = new SqlCommand("select * from address_book where name='" + checkedListBox1.Text + "'", con);
- SqlDataReader dr;
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- textBox1.Text += Convert.ToString(dr["id"] + ",");
- }
- dr.Close();
- }
- private void textBox1_Enter(object sender, EventArgs e)
- {
- ToolTip tt = new ToolTip();
- tt.SetToolTip(textBox1, "sorry");
- }
- }
- private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
- private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
- {
- StringBuilder stringBuilder = new StringBuilder();
- foreach (var item in checkedListBox1.CheckedItems)
- {
- SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
- con.Open();
- SqlCommand cmd = new SqlCommand(string.Format("select * from address_book where name='{0}'", item), con);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- stringBuilder.Append(Convert.ToString(dr["id"] + ","));
- }
- dr.Close();
- }
- textBox1.Text = stringBuilder.ToString().TrimEnd(',');
- }
- textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
Add Comment
Please, Sign In to add comment