By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

Exception error when importing datagridview to Oracle

P: 8
Hi, I'm trying to update a datagrid view table to the Oracle DB.
This is my code so far....


Expand|Select|Wrap|Line Numbers
  1. // Connection to Oracle DB   
  2.  int connectionCounter = 0;   
  3.                 bool boolUpdateData = true;   
  4.                 while (boolUpdateData && connectionCounter < 3)   
  5.                 {   
  6.                     try   
  7.                     {   
  8.                         localConnection = new OracleConnection(localFunction.localConnectionString);   
  9.                         localConnection.Open();   
  10.  
  11.                         boolUpdateData = false;   
  12.                     }   
  13.                     catch (Exception localException)   
  14.                     {   
  15.                         localFunction.WriteEventLog(localException.ToString(), "OPCAlarmConfig");   
  16.                     }   
  17.                     connectionCounter++;   
  18.                 }   
  19.  
  20.                 localSQL = @"SELECT * FROM SYS_LINE";   
  21.                 localFunction.ExecuteOracleNonQuery(localSQL, localConnection, "OPCAlarmConfig");   
  22.  
  23. // Update Oracle DB   
  24.          try {   
  25.             OracleCommandBuilder cb = new OracleCommandBuilder(oleda);   
  26.             userTable = ds.Tables["SYS_LINE"];   
  27.             oleda.Fill(ds,"SYS_LINE");   
  28.             excelGridView.DataSource = ds.Tables[0];   
  29.             oleda.Update(ds, "SYS_LINE");   
  30.               }   
  31.                 catch (Exception imptoracle)   
  32.                 { MessageBox.Show(imptoracle.ToString()); }   
  33.             }   
  34.  

This exception error "Object reference not set to an instance of an object" kept appearing on the "oleda.Fill(ds,"SYS_LINE");" line

Can anyone help?
Feb 18 '09 #1
Share this Question
Share on Google+
2 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
Well, you haven't shown us in this code where you instantiate your DataAdapter object (oleda). Without that, I can't tell exactly whats wrong.

It looks like you either never instantiated it, or you never set it's select command, based on the error.
Feb 18 '09 #2

P: 8
This is where my form loads.
Expand|Select|Wrap|Line Numbers
  1. public void displayexcel_Load(object sender, EventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 string connString = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + gotdirectory + @";Extended Properties=""Excel 8.0;HDR=YES;""";
  6.                 OleDbConnection oledbConn = new OleDbConnection(connString);
  7.                 oledbConn.Open();
  8.                 OleDbCommand cmd = new OleDbCommand("SELECT * FROM [A2:O36]", oledbConn);
  9.                 OleDbDataAdapter oleda = new OleDbDataAdapter();
  10.                 oleda.SelectCommand = cmd;
  11.                 oleda.Fill(ds);
  12.                 userTable = ds.Tables[0];
  13.                 excelGridView.DataSource = ds.Tables[0].DefaultView;
  14.                 excelGridView.ReadOnly = true;
  15.                 oledbConn.Close();
  16.             }
  17.             catch (Exception displayerror)
  18.             {
  19.                 MessageBox.Show(displayerror.ToString());
  20.             }
  21.         }
  22.  
Feb 19 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.