Re: Data bound fruit basket with SQL Server Compact Edition

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Thu, 6 Dec 2007 08:59:51 -0500 (EST)

Unfortunately, I have now found what is a significatnt disadvantage for
me.  I had assumed that a command-line interface was available in addition
to the VS IDE support, e.g., using the SqlCmd.exe utility distributed with
SQL Server 2005 Express.  That, or any other present command-line utility,
however, does not support the .sdf database format of the Compact Edition.
Although I am glad for the IDE support, I am reluctant to do much work
with a database that does not also offer manipulation by the command line,
since other databases are available with such support.

Regarding SQLite, I took another look at the .NET wrapper and found
that it has a basic security feature.  One can set (or change) a
database password, which encrypts the file.  I will post a program
that illustrates this.

Jamal
On Wed, 5 Dec 2007, Octavian Rasnita wrote:

> Date: Wed, 5 Dec 2007 20:41:58 +0200
> From: Octavian Rasnita <orasnita@xxxxxxxxx>
> Reply-To: programmingblind@xxxxxxxxxxxxx
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Re: Data bound fruit basket with SQL Server Compact Edition
>
> This seems to be a good advantage when comparing it with SQLite.
> If it would allow fulltext indexes, it would be really good...
>
> Octavian
>
> ----- Original Message -----
> From: "Jamal Mazrui" <empower@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Wednesday, December 05, 2007 6:34 PM
> Subject: Re: Data bound fruit basket with SQL Server Compact Edition
>
>
> > Yes, seccurity capabilities seem fairly strong, including built-in
> > encryption mechanisms, etc.
> >
> > Jamal
> > On Wed, 5 Dec 2007, Octavian Rasnita wrote:
> >
> >> Date: Wed, 5 Dec 2007 17:31:32 +0200
> >> From: Octavian Rasnita <orasnita@xxxxxxxxx>
> >> Reply-To: programmingblind@xxxxxxxxxxxxx
> >> To: programmingblind@xxxxxxxxxxxxx
> >> Subject: Re: Data bound fruit basket with SQL Server Compact Edition
> >>
> >> Can this database use authentication with a username and a password?
> >>
> >> Octavian
> >>
> >> ----- Original Message -----
> >> From: "Jamal Mazrui" <empower@xxxxxxxxx>
> >> To: <programmingblind@xxxxxxxxxxxxx>
> >> Sent: Wednesday, December 05, 2007 5:05 PM
> >> Subject: Re: Data bound fruit basket with SQL Server Compact Edition
> >>
> >>
> >> > After studying documentation further, below is a shorter version that
> >> > uses
> >> > a ResultSet cursor instead of CommandBuilder, DataAdapter, DataTable,
> >> > and
> >> > the transfer ID event handler.
> >> >
> >> > Jamal
> >> >
> >> > /*
> >> > content of resultset.cs
> >> > Fruit Basket program in C# 3.0 with SQL Server Compact Edition 3.5
> >> > Public domain by Jamal Mazrui
> >> > */
> >> >
> >> > // Import namespaces
> >> > using System;
> >> > using System.Data;
> >> > using System.Data.SqlServerCe;
> >> > using System.IO;
> >> > using System.Windows.Forms;
> >> >
> >> > // Define class
> >> > class FruitBasket {
> >> >
> >> > // Define entry point of program
> >> > static void Main() {
> >> > // Define full path of database file
> >> > var sSdf = Path.Combine(Application.StartupPath, "resultset.sdf");
> >> > // Define database connection string
> >> > var sConnect = "Data Source=" + sSdf;
> >> >
> >> > // Define connection
> >> > using (var connect = new SqlCeConnection(sConnect)) {
> >> > var sTable = "Basket";
> >> > var sColumn = "Fruit";
> >> >
> >> > // Open connection if database exists, else create it
> >> > if (File.Exists(sSdf)) connect.Open();
> >> > else {
> >> > using (var engine = new SqlCeEngine(sConnect)) engine.CreateDatabase();
> >> > connect.Open();
> >> > var sCreate = "create table " + sTable + " (ID int identity primary
> >> > key, "
> >> > + sColumn + " nvarchar(20))";
> >> > var createCommand = new SqlCeCommand(sCreate, connect);
> >> > createCommand.ExecuteNonQuery();
> >> > } // if database exists
> >> >
> >> > // Define result set
> >> > var sSelect = "select * from " + sTable;
> >> > var selectCommand = new SqlCeCommand(sSelect, connect);
> >> > var resultSet =
> >> > selectCommand.ExecuteResultSet(ResultSetOptions.Scrollable
> >> > | ResultSetOptions.Updatable);
> >> >
> >> > // Create controls;
> >> > var tlp = new TableLayoutPanel {ColumnCount = 3, RowCount = 2};
> >> > var lblFruit = new Label {Text = "&Fruit:", Parent = tlp};
> >> > var txtFruit = new TextBox {Parent = tlp};
> >> > var btnAdd = new Button {Text = "&Add", Parent = tlp};
> >> > var lblBasket = new Label {Text = "&Basket:", Parent = tlp};
> >> > var lstBasket = new ListBox {DataSource = resultSet, DisplayMember =
> >> > sColumn, ValueMember = sColumn, Parent = tlp};
> >> > var btnDelete = new Button {Text = "&Delete", Parent = tlp};
> >> >
> >> > // Define Add event handler;
> >> > btnAdd.Click += (o, e) => {
> >> > var sFruit = txtFruit.Text.Trim();
> >> > if (sFruit.Length == 0) MessageBox.Show("No fruit to add!", "Alert");
> >> > else {
> >> > var record = resultSet.CreateRecord();
> >> > record.SetString(1, sFruit);
> >> > resultSet.Insert(record);
> >> > int iFruit = lstBasket.Items.Count - 1;
> >> > lstBasket.SelectedIndex = iFruit;
> >> > txtFruit.Clear();
> >> > } // if fruit to add
> >> > }; // add
> >> >
> >> > // Define Delete event handler;
> >> > btnDelete.Click += (o,e) => {
> >> > int iFruit = lstBasket.SelectedIndex;
> >> > if (iFruit == -1) MessageBox.Show("No fruit to delete!", "Alert");
> >> > else {
> >> > resultSet.Delete();
> >> > if (iFruit == lstBasket.Items.Count) iFruit--;
> >> > resultSet.ReadAbsolute(iFruit);
> >> > } // if fruit to delete
> >> > }; // delete
> >> >
> >> > // Finalize dialog;
> >> > var dlg = new Form {Text = "Fruit Basket", AcceptButton = btnAdd,
> >> > StartPosition = FormStartPosition.CenterScreen, AutoSize = true,
> >> > AutoSizeMode = AutoSizeMode.GrowAndShrink};
> >> > dlg.Controls.Add(tlp);
> >> > // Define closing event handler
> >> > dlg.Closing += (o, e) => e.Cancel = (MessageBox.Show("Close program?",
> >> > "Confirm", MessageBoxButtons.YesNo) == DialogResult.No);
> >> > dlg.ShowDialog();
> >> > connect.Close();
> >> > } // using connect
> >> > } // Main method
> >> > } // FruitBasket class
> >> >
> >> > // End of resultset.cs
> >> >
> >> > __________
> >> > View the list's information and change your settings at
> >> > //www.freelists.org/list/programmingblind
> >> >
> >>
> >> __________
> >> View the list's information and change your settings at
> >> //www.freelists.org/list/programmingblind
> >>
> > __________
> > View the list's information and change your settings at
> > //www.freelists.org/list/programmingblind
> >
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: