using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace Office
{
public partial class VisualRecursosHumanos : Form
{
private OleDbConnection bookConn;
private OleDbCommand oleDbCmd = new OleDbCommand();
private String connParam = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\office\office\\app_data\office.mdb;Persist Security Info=False";
public VisualRecursosHumanos()
{
bookConn = new OleDbConnection(connParam);
InitializeComponent();
}
DataSet ds;
int rno;
private void button71_Click(object sender, EventArgs e)
{
bookConn.Open();
oleDbCmd.Connection = bookConn;
oleDbCmd.CommandText = "insert into funcionario (code, nome, saudacoes, abreviado, data, idade, matricula, tipocadastro, departamento, CP, classificacao, banco, agencia, contacorrente, foto) values ('" + this.txtCodCadastFunc.Text + "','" + this.txtNomesCadastFunc.Text + "','" + this.cbxSaudacoesCadastFunc.Text + "','"
+ this.txtAbreviadoCadastFunc.Text + "','" + this.DateNascimCadastFuncionario.Value + "','" + this.lblIdadeCadastFunc.Text + "', '" + this.txtMatricCadastFunc.Text + "','" + this.cbxTipoCadastroCadastFunc.Text + "', '"+ this.txtDepartamentoCadastFunc.Text + "','"
+ this.txtCPCadastFunc.Text + "','" + this.cbxClassificacaoCadastFunc.Text + "','" + this.cbxBancoCadastFunc.Text + "','" + this.txtAgenciaCadastFunc.Text + "','" + this.txtCorrenteCadastFunc.Text +"', '"+ this.picBxCadastFunc.Image + "');";
int temp = oleDbCmd.ExecuteNonQuery();
if (temp > 0)
{
txtNomesCadastFunc.Text = null;
txtCodCadastFunc.Text = null;
cbxSaudacoesCadastFunc.Text = null;
txtAbreviadoCadastFunc.Text = null;
DateNascimCadastFuncionario.Value.ToString();
lblIdadeCadastFunc.Text = null;
txtMatricCadastFunc.Text = null;
cbxTipoCadastroCadastFunc.Text = null;
txtDepartamentoCadastFunc.Text = null;
picBxCadastFunc.Image.ToString();
MessageBox.Show("Record Successfuly Added");
}
else
{
MessageBox.Show("Record Fail to Added");
}
bookConn.Close();
}
private void VisualRecursosHumanos_Load(object sender, EventArgs e)
{
NavigateRecords();
}
private void NavigateRecords()
{
txtNomesCadastFunc.Text = ds.Tables["funcionario"].Rows[rno][0].ToString();
}
private void btnNextEnderEnderecFunc_Click(object sender, EventArgs e)
{
if (ds.Tables[0].Rows.Count > 0)
{
rno = 0;
NavigateRecords();
}
else
MessageBox.Show("no records");
}
}
}

Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 11, 2014, 8:32 PM EDT
Generally this error comes when you trying to access property or method of null object...
In which line you got the error in above code?
Mfwamba Tshimanga155 reputationPosted Sep 12, 2014, 2:36 PM EDT
private void btnNextEnderEnderecFunc_Click(object sender, EventArgs e)
{
if (ds.Tables[0].Rows.Count > 0) // It's here in this line where appear the error message
{
rno = 0;
NavigateRecords();
}
Mfwamba Tshimanga155 reputationPosted Sep 15, 2014, 2:18 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 15, 2014, 2:26 AM EDT
sorry for the delay...
First of all check the value of ds and check whether it has any data table...
to void the error try following code...
private void btnNextEnderEnderecFunc_Click(object sender, EventArgs e)
{
if (ds!=null && ds.tables.Count >0 &&ds.Tables[0].Rows.Count > 0)
{
rno = 0;
NavigateRecords();
}
hope this will help you