public DACustomer(BOCustomer cus)

{

// A reference of the business object class

}

//standard dataset function that adds a new customer

public void Add(BOCustomer cus)

{

String str = BuildAddString(cus);

OpenCnn();

//Open command option - cnn parameter is imporant

OleDbCommand cmd = new OleDbCommand(str,cnn);

//execute connection

cmd.ExecuteNonQuery();

// close connection

CloseCnn();

}

//standard dataset function that updates

//details of a customer based on ID

public void Update(BOCustomer cus)

{

OpenCnn();

String selectStr = "UPDATE " + thisTable +

" set " + cus_LName + " = '" + cus.LName + "'" +

", " + cus_FName + " = '" + cus.FName + "'" +

", " + cus_Address + " = '" + cus.Address + "'" +

", " + cus_Tel + " = '" + cus.Tel + "'" +

" where cus_ID = '" + cus.cusID + "'";

OleDbCommand cmd = new OleDbCommand(selectStr,cnn);

cmd.ExecuteNonQuery();   

CloseCnn();

}

//standard dataset function that finds and

//return the detail of a customer in a dataset

public DataSet Find(String argStr)

{

DataSet ds=null;

try

{

OpenCnn();     

String selectStr = "select * from " + thisTable +

" where cus_ID = '" + argStr + "'";

OleDbDataAdapter da =

new OleDbDataAdapter(selectStr,cnn);

ds = new DataSet();

da.Fill(ds,thisTable);

CloseCnn();             

}

catch(Exception e)

{

String Str = e.Message;

}

return ds;

}

private void OpenCnn()

{

// initialise connection

String cnnStr = CnnStr;

cnn = new OleDbConnection(cnnStr);

// open connection

cnn.Open();

}

private void CloseCnn()

{

// 5- step five

cnn.Close();

}      

// just a supporting function that builds

// and return the insert string for dataset.

private String BuildAddString(BOCustomer cus)

{

// these are the constants as

// set in the top of this module.

strTable="Insert into " + thisTable;

strFields=" (" + cus_ID +

"," + cus_LName +

"," + cus_FName +

"," + cus_Address +

"," + cus_Tel + ")";          

//these are the attributes of the

//customer business object.

strValues= " Values ( '" + cus.cusID +

"' , '" + cus.LName +

"' , '" + cus.FName +

"' , '" + cus.Address +

"' , '" + cus.Tel + "' )";

insertStr = strTable + strFields + strValues;         

return insertStr;         

}

}

}

相关文章:

  • 2021-08-09
  • 2021-07-31
  • 2022-12-23
  • 2022-01-04
猜你喜欢
  • 2021-10-01
  • 2021-06-01
  • 2021-12-02
  • 2021-12-17
相关资源
相似解决方案