Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- System.NullReferenceException ocorrido
- HResult=0x80004003
- Message=Referência de objeto não definida para uma instância de um objeto.
- Source=ProjetoAlpha
- StackTrace:
- em ProjetoAlpha.frmProduto.btnGravar_Click(Object sender, EventArgs e) em C:UserswilliansourcereposProjetoAlphaProjetoAlphafrmProduto.cs:linha 29
- em System.Windows.Forms.Control.OnClick(EventArgs e)
- em System.Windows.Forms.Button.OnClick(EventArgs e)
- em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
- em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
- em System.Windows.Forms.Control.WndProc(Message& m)
- em System.Windows.Forms.ButtonBase.WndProc(Message& m)
- em System.Windows.Forms.Button.WndProc(Message& m)
- em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
- em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
- em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
- em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
- em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
- em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
- em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
- em System.Windows.Forms.Application.Run(Form mainForm)
- em ProjetoAlpha.Program.Main() em C:UserswilliansourcereposProjetoAlphaProjetoAlphaProgram.cs:linha 19
- using System;
- using Npgsql;
- using System.Data;
- namespace ProjetoAlpha
- {
- class DAL
- {
- static string serverName = "localhost";
- static string port = "5432";
- static string userName = "postgres";
- static string password = "adm";
- static string databaseName = "dbestoque";
- NpgsqlConnection conn = null;
- string ConnString = null;
- public DAL()
- {
- ConnString = String.Format("Server={0};Port={1};User Id{2};Password={3};Database={4};",
- serverName, port, userName, password, databaseName);
- }
- public DataTable GetTodosRegistros()
- {
- DataTable dt = new DataTable();
- try
- {
- using (conn = new NpgsqlConnection(ConnString))
- {
- conn.Open();
- string cmdSeleciona = "SELECT * FROM estoque order by id_produto";
- using (NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmdSeleciona, conn))
- {
- da.Fill(dt);
- }
- }
- }
- catch (NpgsqlException ex)
- {
- throw ex;
- }
- finally
- {
- conn.Close();
- }
- return dt;
- }
- public DataTable GetRegistroPorId(int id)
- {
- DataTable dt = new DataTable();
- try
- {
- using (NpgsqlConnection conn = new NpgsqlConnection(ConnString))
- {
- conn.Open();
- string cmdSeleciona = "SELECT * FROM ESTOQUE WHERE codigo =" + id;
- using (NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmdSeleciona, conn))
- {
- da.Fill(dt);
- }
- }
- }
- catch (NpgsqlException ex)
- {
- throw ex;
- }
- catch(Exception ex)
- {
- throw ex;
- }
- finally
- {
- conn.Close();
- }
- return dt;
- }
- public void InserirRegistros(string nome, int codigo, int minimo, int maximo, int qtd, DateTime data)
- {
- try
- {
- using (NpgsqlConnection conn = new NpgsqlConnection(ConnString))
- {
- conn.Open();
- string cmdInserir = String.Format("INSERT INTO ESTOQUE(nome,codigo,minimo,maximo,quantidade,dataEntrada) " +
- "VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')", nome, codigo, minimo, maximo, qtd, data);
- using (NpgsqlCommand cmd = new NpgsqlCommand(cmdInserir, conn))
- {
- cmd.ExecuteNonQuery();
- }
- }
- }catch(NpgsqlException ex)
- {
- throw ex;
- }catch(Exception ex)
- {
- throw ex;
- }
- finally
- {
- conn.Close();
- }
- }
- }
- }
- private void btnGravar_Click(object sender, EventArgs e)
- {
- DAL acesso = new DAL();
- try
- {
- acesso.InserirRegistros(txtNomeProduto.Text, Convert.ToInt32(txtCodigo.Text), Convert.ToInt32(txtMinimo.Text), Convert.ToInt32(txtMaximo.Text), Convert.ToInt32(txtEntrada.Text), dtpData.Value);
- }catch(Exception ex)
- {
- throw ex;
- }
- finally
- {
- MessageBox.Show("Cadastrado com sucesso!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement