1

这是我的代码示例,我从 excel 导入数据并使用公共数据集在 datagridview 中查看。但是当我尝试将其插入到 oracle 表 RTGS_IMPORT 中时,它没有给出任何错误,但也没有导入:| 请帮助..只是一个有抱负的初学者:D

private void button1_Click(object sender, EventArgs e)
    {


        string insqry = "INSERT INTO RTGS_IMPORT (BANK_ID,BANK,IFSC,BRANCHNAME,ADDRESS) VALUES (:BANK_ID,:BANK,:IFSC,:BRANCHNAME,:ADDRESS)";

        OracleConnection conn = new OracleConnection("Data Source=KBETEST;Persist Security Info=True;User ID=dbo;Password=dbo123;Unicode=True");
        conn.Open();
        OracleTransaction trans = conn.BeginTransaction();
        OracleDataAdapter ad = new OracleDataAdapter();
        ad.InsertCommand = new OracleCommand(insqry, conn);

        foreach (DataRow drrow in ds.Tables["A"].Rows)
        { 

            ad.InsertCommand.Parameters.Add(new OracleParameter(":BANK_ID", drrow["BANK_ID"]));
            ad.InsertCommand.Parameters.Add(new OracleParameter(":BANK", drrow["BANK NAME"]));
            ad.InsertCommand.Parameters.Add(new OracleParameter(":IFSC", drrow["IFSC"]));
            ad.InsertCommand.Parameters.Add(new OracleParameter(":BRANCHNAME", drrow["BRANCH NAME"]));
            ad.InsertCommand.Parameters.Add(new OracleParameter(":ADDRESS", drrow["ADDRESS"]));

        }
        conn.Dispose();


    }

提前谢谢你们!

4

1 回答 1

0

设置参数后必须执行命令:

ad.InsertCommand.ExecuteNonQuery();

所以:

foreach (DataRow drrow in ds.Tables["A"].Rows)
        { 
        ad.InsertCommand.Parameters.Add(new OracleParameter(":BANK_ID", drrow["BANK_ID"]));
        ad.InsertCommand.Parameters.Add(new OracleParameter(":BANK", drrow["BANK NAME"]));
        ad.InsertCommand.Parameters.Add(new OracleParameter(":IFSC", drrow["IFSC"]));
        ad.InsertCommand.Parameters.Add(new OracleParameter(":BRANCHNAME", drrow["BRANCH NAME"]));
        ad.InsertCommand.Parameters.Add(new OracleParameter(":ADDRESS", drrow["ADDRESS"]));
        ad.InsertCommand.ExecuteNonQuery();
    }

请参阅此处:在 C# 和 Oracle 中执行更新

于 2013-10-28T10:11:24.753 回答