C# (VS2019) DeskTopApplication [SQL(MS-ACCESS365)パラメータ版インサート] (2020-02)
using System;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Drawing;
String ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\shn\source\repos\MAILDBSYSTEM\MailDB.accdb";
OleDbConnection conn;
OleDbCommand comm;
string sqlstr = "INSERT INTO USR (USR,TEL,ADDS) VALUES(@USR,@TEL,@ADDS)";
conn = new OleDbConnection(ConnectionString);
conn.Open();
try {
comm = new OleDbCommand(sqlstr, conn);
OleDbParameter param = comm.CreateParameter();
param.ParameterName = "@USR3";
param.OleDbType = OleDbType.VarChar;
param.Value = textBox1.Text;
comm.Parameters.Add(param);
param = comm.CreateParameter();
param.ParameterName = "@TEL";
param.OleDbType = OleDbType.VarChar;
param.Value = textBox2.Text;
comm.Parameters.Add(param);
param = comm.CreateParameter();
param.ParameterName = "@ADDS";
param.OleDbType = OleDbType.VarChar;
param.Value = textBox3.Text;
comm.Parameters.Add(param);
comm.ExecuteNonQuery();
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
finally {
conn.Close();
conn.Dispose();
}
戻る