Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnSave_Click(object sender, EventArgs e)
- {
- OleDbConnection Conn = new OleDbConnection();
- try
- {
- string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ Directory.GetCurrentDirectory() +"\dvd_manager.accdb;Persist Security Info=False;";
- Conn.ConnectionString = conn;
- Conn.Open();
- int i = cbbLocatie.SelectedIndex + 65;
- char c = (char)i;
- string sql = "INSERT INTO DVD (titel, locatie)VALUES(@titel, @locatie)";
- OleDbCommand Com = new OleDbCommand();
- Com.CommandText = sql;
- Com.Connection = Conn;
- OleDbParameter Param = new OleDbParameter("@titel", txtTitle.Text);
- Com.Parameters.Add(Param);
- Param = new OleDbParameter("@locatie", c);
- Com.Parameters.Add(Param);
- Com.ExecuteNonQuery();
- Conn.Close();
- MessageBox.Show("Data is opgeslagen " + sql);
- }
- catch (Exception ex)
- {
- MessageBox.Show("Fout opgetreden: " + ex.Message);
- }
- finally
- {
- Conn.Close();
- }
- }
- try
- {
- string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ Directory.GetCurrentDirectory() +"\dvd_manager.accdb;Persist Security Info=False;";
- Conn.ConnectionString = conn;
- // Create object
- Medium M = new Medium();
- int i = cbbLocatie.SelectedIndex + 65;
- char c = (char)i;
- M.Location = c;
- M.Title = txtTitle.Text;
- Conn.Open();
- string sql = "INSERT INTO DVD (titel, locatie)VALUES(@titel, @locatie)";
- OleDbCommand Com = new OleDbCommand();
- Com.CommandText = sql;
- Com.Connection = Conn;
- OleDbParameter Param1 = new OleDbParameter("@titel", M.Title);
- Com.Parameters.Add(Param1);
- OleDbParameter Param2 = new OleDbParameter("@locatie", M.Location);
- Com.Parameters.Add(Param2);
- int ret = Com.ExecuteNonQuery();
- Conn.Close();
- MessageBox.Show("Data is opgeslagen " + ret);
- }
- catch (OleDbException ex)
- {
- MessageBox.Show(ex.Message);
- }
- catch (Exception ex)
- {
- MessageBox.Show("Fout opgetreden: " + ex.Message);
- }
- finally
- {
- Conn.Close();
- }
- // some code
- Conn.Open();
- string sql = "INSERT INTO DVD (titel, locatie)VALUES(?, ?)";
- OleDbCommand Com = new OleDbCommand();
- Com.CommandText = sql;
- Com.Connection = Conn;
- OleDbParameter Param1 = new OleDbParameter("@p1", OleDbType.VarChar, 1);
- Param1.Value = M.Title;
- Com.Parameters.Add(Param1);
- OleDbParameter Param2 = new OleDbParameter("@p2", OleDbType.VarChar, 255);
- Param2.Value = M.Location;
- Com.Parameters.Add(Param2);
- int ret = Com.ExecuteNonQuery();
- Conn.Close();
- // morde code
- string sql = "INSERT INTO DVD (titel, locatie)VALUES(?, ?)";
- using(OleDbConnection connection = new OleDbConnection(CONNECTION_STRING))
- {
- using(OleDbCommand command = connection.CreateCommand())
- {
- command.CommandType = CommandType.Text;
- command.CommandText = "INSERT INTO DVD(title,locatie)VALUES(?,?)";
- command.Parameters.Add("@p1", OleDbType.VarChar, 1).Value = M.Title;
- command.Parameters.Add("@p2", OleDbType.VarChar, 255).Value = M.Location;
- connection.Open();
- int ret = command.ExecuteNonQuery();
- }
- }
- {
- OleDbCommand myCommand;
- DbParameter parameter = myCommand.CreateParameter();
- parameter.ParameterName = paramAT;
- parameter.Value = paramTxt;
- myCommand.Parameters.Add(parameter);
- }
- {
- try
- {
- string strSqldvd ="INSERT INTO DVD(title,locatie)VALUES(@title,@locate?)";
- myCommand = (OleDbCommand)dbconn.MyProvider.CreateCommand();
- dbconn.MyConnection.Open();
- myCommand.Connection = dbconn.MyConnection;
- myCommand.CommandText = strSqldvd;
- setParameter("@title",M.Title );
- setParameter("@locate", M.Location);
- }
- catch (Exception)
- {
- throw new ArgumentException();
- }
- int count = myCommand.ExecuteNonQuery();
- dbconn.MyConnection.Close();
- return count;
- }
Add Comment
Please, Sign In to add comment