class item_Electronic
{
string eID;
public string ID
{
get { return eID; }
set { eID = value; }
}
string eType;
public string Type
{
get { return eType; }
set { eType = value; }
}
string eManufacturer;
public string Manufacturer
{
get { return eManufacturer; }
set { eManufacturer = value; }
}
string eMake;
public string Make
{
get { return eMake; }
set { eMake = value; }
}
string eModelNo;
public string ModelNo
{
get { return eModelNo; }
set { eModelNo = value; }
}
int ePrice;
public int Price
{
get { return ePrice; }
set { ePrice = value; }
}
int eQuantity;
public int Quantity
{
get { return eQuantity; }
set { eQuantity = value; }
}
//customized Constructor which will enable itx connection to database
public item_Electronic()
{
connectDB();
}
//Properties supporting Methods of Object
OleDbConnection myConn;
OleDbCommand myComm;
string queryString;
public void connectDB()
{
myConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\rummykhan\MCS\Spring 2013\Object Oriented Programming\My Apps\MyProject\c Projects\My Class Project\Projects Database\IMSDatabase.accdb");
}
public void insert(item_Electronic product)
{
try
{
queryString = "Insert INTO Electronics (eID,eType,eManufacturer,eMake,eModelNo,ePrice,eQuantity) Values('" + product.ID + "','" + product.Type
+ "','" + product.Manufacturer + "','" + product.Make + "','" + product.ModelNo + "','" + product.Price
+ "','" + product.Quantity + "')";
myComm = new OleDbCommand(queryString, myConn);
myConn.Open();
myComm.ExecuteNonQuery();
MessageBox.Show("Test");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (myConn!=null)
{
myConn.Close();
}
}
}
}
我正在处理应用程序,并且我在课堂上封装了我的每个领域,我想知道这是否是一个好习惯。提前感谢