Ali G

Ali G

  • NA
  • 51
  • 38.5k

GETTING DATA FROM SQL COMPACT

Jan 2 2013 6:25 AM

I have 2 listboxes in a form. They uses data bound items.
My listboxes gets the values problem free. My database is here:


My databse properties including path is here:



In my software philosophy user select a value (comes from fldUnitName) from listBox1 and according to selected item I must get the fldCoefficient from the table. And I will assign this fldCoefficient value to a double like Double DoubleKatsayi1= (The Value comes from fldCoefficient)

And After same process for listBox2 selection I must have a DoubleKatsayi2.

I know all codes are a few lines but because I am newbee I couldn't write. FOr a starting point I am writing some codes here. Can you edit it?

//CODES BEGIN:
using System.Data.SqlServerCe;

SqlCeConnection conn = new SqlCeConnection("Data Source=unitsdb.sdf");
conn.Open();
string sql1 = "SELECT * FROM tblAcceleration WHERE fldUnitName =" + "' listBox1.SelectedItem +'";
string sql2 = "SELECT * FROM tblAcceleration WHERE fldUnitName =" + "' listBox2.SelectedItem +'";

SqlCeCommand cmd1 = new SqlCeCommand(sql1, conn);
SqlCeDataReader r1 = cmd1.ExecuteReader();
 
SqlCeCommand cmd2 = new SqlCeCommand(sql2, conn);
SqlCeDataReader r2 = cmd2.ExecuteReader();

conn.Close();

Double DoubleKatsayi1 = .............;
Double DoubleKatsayi2 = .............;
//CODES END

Note: To see the large images drag and drops them to the browser.