1

C# winform でテーブルを更新するために ODP.net を使用しています。Oracle テーブルの制約に novalidate があると、動的 SQL エラーが発生します。それがない場合、削除/編集は正常に機能します。

以下のオプション以外でこの問題を修正する方法を教えてください。2. Oracle テーブルの constarint 内の novalidate を削除します。


Oracle テーブルの制約:

ALTER TABLE "table1" ADD CONSTRAINT "PK_table1" PRIMARY KEY ("EMP_ID") ENABLE NOVALIDATE;

C# コード:

using Oracle.DataAccess.Client;

public partial class Form1 : Form
    {
        OracleConnection OraConn;
        OracleDataAdapter FOraDataAdapt;
        DataTable OraDataTable;
        BindingSource FBindSource;
        int RecNo;

        public Form1()
        {
            InitializeComponent();
            OraConn = new OracleConnection("Data Source=ORCL1;User Id=123;Password=123;");
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                OraConn.Open();

                OracleCommand FOraCommand = new OracleCommand("select * from table1", OraConn);
                FOraDataAdapt = new OracleDataAdapter(FOraCommand);                   OracleCommandBuilder FOraCommandBuilder = new OracleCommandBuilder(FOraDataAdapt);
                OraDataTable = new DataTable();

                DataTable TableSchema = new DataTable();
                FOraDataAdapt.Fill(OraDataTable);
                FOraDataAdapt.FillSchema(TableSchema, System.Data.SchemaType.Source);

                FBindSource = new BindingSource();
                FBindSource.DataSource = OraDataTable;

                grdView.DataSource = FBindSource; 

            }
            catch (Exception Exp)
            {
                MessageBox.Show(Exp.Message);
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                RecNo = FBindSource.Position;
                FBindSource.RemoveAt(RecNo);
                FOraDataAdapt.Update(OraDataTable);            
                OraDataTable.Rows[RecNo].AcceptChanges();
            }
            catch (Exception Exp)
            {
                MessageBox.Show(Exp.Message);
            }
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            RecNo = FBindSource.Position;
            OraDataTable.Rows[RecNo].BeginEdit();
        }

        private void btnPost_Click(object sender, EventArgs e)
        {
            try
            {
                FBindSource.EndEdit();
                FOraDataAdapt.Update(OraDataTable);
                OraDataTable.Rows[RecNo].AcceptChanges();
            }
            catch (Exception Exp)
            {
                MessageBox.Show(Exp.Message);
            }
        }
    }
4

0 に答える 0