title: Select Data from Database Depend on Items in Listbox c#
body: <p>I have a problem to select data depending on all items in a Listbox. Here, in my Listbox there are two items, named Kamera125 and Kamera127. Kamera125 and Kamera127 exist in a MS Access Database. So, when I run my program, I want my program to select Kamera125 and Kamera127 from listbox that connected to MS Access. I used the following query</p>
  
  <pre><code>string selectsemuakoordgaris = "select * from koordinatgaris where namakamera='" + listBox3.Text + "'"; 
  </code></pre>
  
  <p>and it doesn't work.</p>
  
  <p>These is my codes :</p>
  
  <pre><code>            private void ProsesSemuaKamera()
              {
                  Stopwatch watch = Stopwatch.StartNew();
  
                  Ping ping = new Ping();
                  PingReply pingreply;
  
                  OleDbConnection kon = new OleDbConnection(koneksi);
                  OleDbCommand command = kon.CreateCommand();
                  kon.Open();
                  string selecturl = "select * from datakamera";
                  command.CommandText = selecturl;
                  OleDbDataReader bacadata = command.ExecuteReader();
  
                  while (bacadata.Read())
                  {
                      int counturl = 0;
                      pingreply = ping.Send(bacadata["ipadd"].ToString());
  
                      if (pingreply.Status == IPStatus.Success)
                      {
                          listBox1.Items.Add(bacadata["ipadd"].ToString());
                          listBox3.Items.Add(bacadata["namakamera"].ToString());
                          textBox1.Text += bacadata["namakamera"].ToString() + Environment.NewLine;
  
                          CaptureSemuaKamera = new Capture(bacadata["urlkamera"].ToString());
                          Application.Idle += new EventHandler(ProcessFrameSemuaKamera);
                      }
                      else if (pingreply.Status != IPStatus.Success)
                      {
                          listBox2.Items.Add(bacadata["ipadd"].ToString());
                      }
                  }
                  kon.Close();
  
                  watch.Stop();
                  File.AppendAllText(@"D:\Dokumen\Alfon\TA Alfon\Waktu Eksekusi Ping.txt", "Waktu eksekusi ping " + DateTime.Now + " :" + " " + watch.Elapsed.TotalMilliseconds.ToString() + Environment.NewLine);
              }
  
  
              private void ProcessFrameSemuaKamera(object sender, EventArgs e)
              {
                  Image&lt;Bgr, Byte&gt; sourceImage = CaptureSemuaKamera.QueryFrame();
                  SourceBox.Image = sourceImage.Bitmap;
  ProsesSemuaKamera();
              }
  
              private void ProsesKameraSemua()
              {
                  Image&lt;Bgr, Byte&gt; sourceImage = CaptureSemuaKamera.QueryFrame();
                  SourceBox.Image = sourceImage.Bitmap;
  
                  OleDbConnection kon = new OleDbConnection(koneksi);
                  OleDbCommand commandkoord = kon.CreateCommand();
                  OleDbCommand commandkoordgaris = kon.CreateCommand();
  
                  kon.Open();
  
                  string selectsemuakoord = "select * from koordinatkotak where namakamera='"+ listBox3.Items + "'";
                  string selectsemuakoordgaris = "select * from koordinatgaris where namakamera='" + listBox3.Items + "'";
                  commandkoord.CommandText = selectsemuakoord;
                  commandkoordgaris.CommandText = selectsemuakoordgaris;
                  OleDbDataReader bacakoord = commandkoord.ExecuteReader();
                  OleDbDataReader bacakoordgaris = commandkoordgaris.ExecuteReader();
  
                  while (bacakoord.Read() &amp;&amp; bacakoordgaris.Read())
                  {
                      #region Perspective projection
  
                      PointF[] srcs = new PointF[4];
                      srcs[0] = new PointF(int.Parse(bacakoord["x1source"].ToString()), int.Parse(bacakoord["y1source"].ToString())); //119, 187
                      srcs[1] = new PointF(int.Parse(bacakoord["x2source"].ToString()), int.Parse(bacakoord["y2source"].ToString())); //242, 181
                      srcs[2] = new PointF(int.Parse(bacakoord["x3source"].ToString()), int.Parse(bacakoord["y3source"].ToString())); //253, 225
                      srcs[3] = new PointF(int.Parse(bacakoord["x4source"].ToString()), int.Parse(bacakoord["y4source"].ToString())); //112, 231
  
                      PointF[] dsts = new PointF[4];
                      dsts[0] = new PointF(int.Parse(bacakoord["x1proj"].ToString()), int.Parse(bacakoord["y1proj"].ToString()));
                      dsts[1] = new PointF(int.Parse(bacakoord["x2proj"].ToString()), int.Parse(bacakoord["y2proj"].ToString()));
                      dsts[2] = new PointF(int.Parse(bacakoord["x3proj"].ToString()), int.Parse(bacakoord["y3proj"].ToString()));
                      dsts[3] = new PointF(int.Parse(bacakoord["x4proj"].ToString()), int.Parse(bacakoord["y4proj"].ToString()));
  
  
                      HomographyMatrix mywarpmat = CameraCalibration.GetPerspectiveTransform(srcs, dsts);
                      Image&lt;Bgr, Byte&gt; newImage = sourceImage.WarpPerspective(mywarpmat, 355, 288, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR, Emgu.CV.CvEnum.WARP.CV_WARP_FILL_OUTLIERS, new Bgr(0, 0, 0));
                      Image&lt;Gray, Byte&gt; newImageGray = newImage.Convert&lt;Gray, Byte&gt;();
  
                      Image&lt;Bgr, Byte&gt; imageToShow = newImage.Copy();
                      Image&lt;Bgr, Byte&gt; imageToShowGaris = newImage.Copy();
  
                      ProjectionBox.Image = newImage.Bitmap; //I want to show Projection result in ProjectionBox. All of coordinates are saved in database. When Kamera125 is choosen, all of coordinates in Kamera125 will be executed. So here, I want to execute all of coordinates of Kamera125 and Kamera127 that is shown in listBox.
  
                      #endregion
                  }
                  kon.Close();
              }
  </code></pre>