Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá,
Tenho um formulário de cadastro que ao clicar em salvar ocorre o seguinte erro:
Referencia de objeto não definida para uma instância de um objeto.
/applications/core/interface/imageproxy/imageproxy.php?img=http://i54.tinypic.com/351a105.jpg&key=44ec35a9fe52332f4db7df2d97fb1abbeccc934fde1d00a58631606a3fd44832" alt="Imagem Postada" />
Aqui está o código da conexao
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FirebirdSql.Data.FirebirdClient;
namespace classe_conexao
{
public class classe_ConexaoFB
{
private string strConexao;
private FbConnection conexao;
public classe_ConexaoFB()
{ }
public classe_ConexaoFB(string strConexao)
{
set_strConexao(strConexao);
Conecta();
}
private void Conectar()
{
conexao = new FbConnection(get_strConexao());
}
public void Conecta()
{
conexao.Open();
}
public void Desconecta()
{
conexao.Close();
}
public FbConnection get_Conexao()
{
return conexao;
}
public void set_strConexao(string strConexao)
{
strConexao = strConexao;
}
public string get_strConexao()
{
return strConexao;
}
}
}
e aqui o código do formulario de cadastro
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 classe_conexao;
using FirebirdSql.Data.FirebirdClient;
namespace Rudekar
{
public partial class CadCliente : Form
{
//INICIO DA CONEXAO
private string caminho;
private string strConexao;
private classe_ConexaoFB conexao_FB;
private FbDataAdapter adapt;
private FbDataReader reader;
private void inicialize()
{
caminho = @"C:\TCC\Programa\Banco\Rudekar.fdb";
strConexao = "User=SYSDBA;" +
"Password=masterkey;" +
"DataBase="+ caminho +"; Dialect=3";
reader = null;
adapt = new FbDataAdapter();
conexao_FB = new classe_ConexaoFB();
}
//FIM DA CONEXAO
public CadCliente()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void CadCliente_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
CadVeiculos myform = new CadVeiculos();
myform.Show();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
//string sql_Insert = "INSERT INTO cad_cliente (cod_cli, nom_cli, end_cli, cpf_cli, tel_cli, cel_cli ) VALUES ('" + @codigo + "', '" + @nome + "', '" + @endereco + "', '" + @cpf + "', '" + @telefone + "', '" + "celular +"');";
string sql_Insert = "INSERT INTO cad_cliente (cod_cli, nom_cli, end_cli, cpf_cli, tel_cli, cel_cli ) VALUES (@codigo,@nome, @endereco, @cpf, @telefone, @celular);";
try
{
conexao_FB.Conecta();
adapt = new FbDataAdapter(sql_Insert, conexao_FB.get_Conexao());
adapt.SelectCommand.Parameters.Clear();
adapt.SelectCommand.Parameters.Add("@codigo", tbcodigo.Text);
adapt.SelectCommand.Parameters.Add("@nome", tbnome.Text);
adapt.SelectCommand.Parameters.Add("@endereco", tbendereco.Text);
adapt.SelectCommand.Parameters.Add("@cpf", tbcpf.Text);
adapt.SelectCommand.Parameters.Add("@telefone", tbtelefone.Text);
adapt.SelectCommand.Parameters.Add("@celular", tbcelular.Text);
adapt.SelectCommand.ExecuteNonQuery();
MessageBox.Show("Cadastro reaizado com sucesso", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception er)
{
MessageBox.Show("Erro ao fazer a inclusão: " + er.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
conexao_FB.Desconecta();
}
}
}
}Carregando comentários...