コード例 #1
0
        int inc     = 0;    // uses to increment or to change current row number

        private void Form1_Load(object sender, EventArgs e)
        {   // instantiating SqlCeConnection object
            con = new System.Data.SqlServerCe.SqlCeConnection();

            // holds location of the database
            con.ConnectionString = "Data Source=C:\\Users\\131311399\\Documents\\databases\\Employees.sdf";

            // opens connection
            con.Open();

            // holds SQL query
            String sql = "SELECT * from tbl_employees";

            // used to fill the DataSet with records from the database
            da = new System.Data.SqlServerCe.SqlCeDataAdapter(sql, con);

            MessageBox.Show("Connection open.");

            // fills DataSet ds1 with table named "Workers"
            da.Fill(ds1, "Workers");

            // calls NavigateRecords() method
            NavigateRecords();

            // counts number of rows in DataSet ds1
            MaxRows = ds1.Tables["Workers"].Rows.Count;

            // calls countRecord() to display record number currently displayed
            countRecord();

            // closes connection
            con.Close();
        }
コード例 #2
0
        /*  This method perform connection to the database
         *
         *  and pull records from the database into a DataSet object
         */

        private System.Data.DataSet MyDataSet()

        {
            System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection(strCon);

            con.Open();

            da_1 = new System.Data.SqlServerCe.SqlCeDataAdapter(sql_string, con);

            dat_set = new System.Data.DataSet();
            da_1.Fill(dat_set, "Default Table");

            con.Close();

            return(dat_set);
        }
コード例 #3
0
        private void PopulateDataSets()
        {
            System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection();
            System.Data.SqlServerCe.SqlCeDataAdapter daHangmanDB;
            DataRow drow;
            DataSet dsWordlist = new DataSet();
            con.ConnectionString = "Data Source=HangmanDB.sdf";

            con.Open();
            daHangmanDB = new System.Data.SqlServerCe.SqlCeDataAdapter("SELECT * From Wordlist", con);
            daHangmanDB.Fill(dsWordlist, "Wordlist");
            con.Close();

            for (int i = 0; i < dsWordlist.Tables["Wordlist"].Rows.Count; ++i)
            {
                drow = dsWordlist.Tables["Wordlist"].Rows[i];
                wordlist.Add(new WordInfo { ID = System.Convert.ToInt32(drow[0]), Cat = drow[1].ToString(), Words = drow[2].ToString() });
            }

            HashSet<String> categories = new HashSet<String>(); //unique list of categories
            foreach (WordInfo wordinf in wordlist) categories.Add(wordinf.Cat);
            comboBoxCategories.DataSource = categories.ToList();
            return;
        }