Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE CLIENTES(
- id_cliente SERIAL PRIMARY KEY NOT NULL,
- tipo INT,
- tipos VARCHAR(10),
- CPF INT
- );
- 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 void InserirClientes(int cb, int cpf)
- {
- using (conn = new NpgsqlConnection(ConnString))
- {
- conn.Open();
- string cmdInserir = String.Format("INSERT INTO CLIENTES(tipo, cpf) VALUES ('{0}', '{1}')", cb, cpf);
- using (NpgsqlCommand cmd = new NpgsqlCommand(cmdInserir, conn))
- {
- cmd.ExecuteNonQuery();
- }
- }
- }
- private void btnGravar_Click(object sender, EventArgs e)
- {
- DAL n = new DAL();
- try
- {
- n.InserirClientes(cbTipo.SelectedIndex, Convert.ToInt16(mskCPF.Text));
- }catch(Exception ex)
- {
- throw ex;
- }
- finally
- {
- MessageBox.Show("Efetuado");
- }
- }
- System.FormatException ocorrido
- HResult=0x80131537
- Message=A cadeia de caracteres de entrada não estava em um formato correto.
- Source=ProjetoAlpha
- StackTrace:
- em ProjetoAlpha.frmCadastros.btnGravar_Click(Object sender, EventArgs e) em C:UserswilliansourcereposProjetoAlphaProjetoAlphafrmCadastros.cs:linha 28
- 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
Add Comment
Please, Sign In to add comment