日期:2014-05-17  浏览次数:20756 次

将gridview的内容写入oracle数据库出错
cs代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OracleClient;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page 
{
     public  DataSet ds;
   protected void  Page_Load(object sender, EventArgs e)
    {
        ds = (DataSet)this.GridView1.DataSource;
        //Session["ds "] = GridView1.DataSource;
       // ds = (DataSet)Session["GridView1"];
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
        OracleConnection conn = new OracleConnection("Data source = xxxx; User Id=xxxx; Password=xxxx;");
         if (conn.State.ToString() == "Closed")
         {
             conn.Open();

         }

         for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
         {
             string danwei = ds.Tables[0].Rows[i][0].ToString();
             string chexing = ds.Tables[0].Rows[i][1].ToString();
             string chehao = ds.Tables[0].Rows[i][2].ToString();
             string jiashiyuan = ds.Tables[0].Rows[i][3].ToString();
             string bqqk = ds.Tables[0].Rows[i][4].ToString();
             string sql = "insert into tcddbqb([danwei],[chexing],[chehao],[jiashiyuan],[bqqk]) values('" + danwei + "','" + chexing + "','" + chehao + "','" + jiashiyuan + "','" + bqqk + "')";
             OracleCommand cmd = new OracleCommand(sql, conn);
             try
             {
                 cmd.ExecuteNonQuery();
             }
             catch (Exception ex)
   &