just a beginner in Programing ... I use a class to handle the connectionstring .
public class DataBase { public OleDbConnection con = new OleDbConnection(); public OleDbCommand cmd = new OleDbCommand();
public void getConnection()
{
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Project\Database\DataBase.mdb";
}
private void btnPrint_Click(object sender, EventArgs e)
{
DataBase db = new DataBase();
db.getConnection();
string Name = txtCostumerName.Text;
string DayorNight = cboSwimming.Text;
string Adult1 = txtAdultCount.Text;
string Kid = txtKidsCount.Text;
string Cottage1 = cboCottageType.Text;
string Room = cboRoomType.Text;
string Total1 = lblCottageTotal.Text;
string Cash1 = txtCashRecieve.Text;
string Change1 = txtChange.Text;
db.con.Open();
OleDbCommand command = new OleDbCommand ("INSERT INTO TicketAndCottage (Cotumer_Name , Swimming, Adult, Kids, Cottage, Room , Total, Cash, Change) Values(@Name , @DayorNight , @Adult1 ,@Kid , @Cottage1 , @Room, @Total1 , @Cash1 , @Change1)");
command.Connection = db.con;
command.CommandType = CommandType.Text;
if (db.con.State == ConnectionState.Open)
{
command.Parameters.Add("@Cotumer_Name", OleDbType.VarChar, 20).Value = Name;
command.Parameters.Add("@Swimming", OleDbType.VarChar, 20).Value = DayorNight;
command.Parameters.Add("@Adult", OleDbType.VarChar, 20).Value = Adult1;
command.Parameters.Add("@Kids", OleDbType.VarChar, 20).Value = Kid;
command.Parameters.Add("@Cottage", OleDbType.VarChar, 20).Value = Cottage1;
command.Parameters.Add("@Room", OleDbType.VarChar, 20).Value = Room;
command.Parameters.Add("@Total", OleDbType.VarChar, 20).Value = Total1;
command.Parameters.Add("@Cash", OleDbType.VarChar, 20).Value = Cash1;
command.Parameters.Add("@Change", OleDbType.VarChar, 20).Value = Change1;
try
{
command.ExecuteNonQuery();
MessageBox.Show("Data Added");
db.con.Close();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Source);
//db.con.Close();
}
}
else
{
MessageBox.Show("Connection Failed");
}
}
and when i click the button i got "Microsoft JET Database Engine"