将公共数据集中的数据插入到oracle表中

时间:2013-10-28 10:05:11

标签: c# oracle visual-studio insert dataset

这是我的代码示例,我使用公共数据集从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();


    }

先谢谢你们!

1 个答案:

答案 0 :(得分: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();
    }

请参阅此处:Execute Update in C# and Oracle