title: Attaching a data source and pictures to a databse using sql command
body: <p>I'm working on an assignment where we are building a housing database. One of my group members sent me code she described as "Not working" and I've fixed it up to a point however, I'm not too familiar with sql command and I still feel that a few things are off here. </p>
  
  <p>Here's the code for inserting: </p>
  
  <pre><code>    private void button2_Click(object sender, EventArgs e)
      {
          try
          {
              SqlConnection con = new SqlConnection("Data Source = Initial Catolog = House_accdb; Integrated Security = true");
              con.Open();
              SqlCommand cmd = new SqlCommand("INSERT INTO Units_With_Tenants(Address, Bedroom, Bathroom, Tenant_Name, Preferences, Picture, Proposed_Rate) VALUES(@Address, @Bedroom, @Bathroom, @Tenant_Name, @Preferences, @Picture, @Proposed_Rate)");
              cmd.Parameters.AddWithValue("@Address", textBox1.Text);
              cmd.Parameters.AddWithValue("@Bedroom", textBox2.Text);
              cmd.Parameters.AddWithValue("@Bathroom", textBox3.Text);
              cmd.Parameters.AddWithValue("@Tenant_Name", textBox4.Text);
              cmd.Parameters.AddWithValue("@Preferences", textBox5.Text);
              cmd.Parameters.AddWithValue("@Picture", File.ReadAllBytes(richTextBox1.Text));
              cmd.Parameters.AddWithValue("@Proposed_Rate", textBox7.Text);
              cmd.ExecuteNonQuery();
              MessageBox.Show("Record inserted successfully");
              con.Close();
          }
          catch(FormatException ex)
          {
              MessageBox.Show("Error. Please enter all fields", "Info");
          }
      }
  </code></pre>
  
  <p>And also here's the code for me attempting to place a picture in the database.</p>
  
  <pre><code>private void button3_Click(object sender, EventArgs e)
      {
          using (OpenFileDialog dlg = new OpenFileDialog())
          {
              dlg.Title = "Open Image";
              dlg.Filter = "bmp files (*.bmp)|*.bmp";
  
              if (dlg.ShowDialog() == DialogResult.OK)
              {
                  PictureBox PictureBox1 = new PictureBox();
                  PictureBox1.Image = new Bitmap(dlg.FileName);
              }
          }
      }
  </code></pre>
  
  <p>Any help is very much appreciated</p>