Mfwamba Tshimanga

Mfwamba Tshimanga

  • NA
  • 155
  • 46.4k

Cant retrieve data...

Sep 11 2014 8:22 PM
Hi!
 
I need to retrieve my data with the button "next" and "back" for example. I cant resolve it. I have this famous message: Object reference not set to an instance of an object.
 

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");

}

}

}

 
 
 
 
 

Answers (4)