Guest User

Untitled

a guest
Oct 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. CREATE TABLE CLIENTES(
  2. id_cliente SERIAL PRIMARY KEY NOT NULL,
  3. tipo INT,
  4. tipos VARCHAR(10),
  5. CPF INT
  6. );
  7.  
  8. class DAL
  9. {
  10. static string serverName = "localhost";
  11. static string port = "5432";
  12. static string userName = "postgres";
  13. static string password = "adm";
  14. static string databaseName = "dbestoque";
  15. NpgsqlConnection conn = null;
  16. string ConnString = null;
  17.  
  18. public DAL()
  19. {
  20. ConnString = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};",
  21. serverName, port, userName, password, databaseName);
  22.  
  23. }
  24. public void InserirClientes(int cb, int cpf)
  25. {
  26. using (conn = new NpgsqlConnection(ConnString))
  27. {
  28. conn.Open();
  29. string cmdInserir = String.Format("INSERT INTO CLIENTES(tipo, cpf) VALUES ('{0}', '{1}')", cb, cpf);
  30.  
  31. using (NpgsqlCommand cmd = new NpgsqlCommand(cmdInserir, conn))
  32. {
  33. cmd.ExecuteNonQuery();
  34. }
  35. }
  36. }
  37.  
  38. private void btnGravar_Click(object sender, EventArgs e)
  39. {
  40. DAL n = new DAL();
  41. try
  42. {
  43. n.InserirClientes(cbTipo.SelectedIndex, Convert.ToInt16(mskCPF.Text));
  44. }catch(Exception ex)
  45. {
  46. throw ex;
  47. }
  48. finally
  49. {
  50. MessageBox.Show("Efetuado");
  51. }
  52.  
  53. }
  54.  
  55. System.FormatException ocorrido
  56. HResult=0x80131537
  57. Message=A cadeia de caracteres de entrada não estava em um formato correto.
  58. Source=ProjetoAlpha
  59. StackTrace:
  60. em ProjetoAlpha.frmCadastros.btnGravar_Click(Object sender, EventArgs e) em C:UserswilliansourcereposProjetoAlphaProjetoAlphafrmCadastros.cs:linha 28
  61. em System.Windows.Forms.Control.OnClick(EventArgs e)
  62. em System.Windows.Forms.Button.OnClick(EventArgs e)
  63. em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
  64. em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
  65. em System.Windows.Forms.Control.WndProc(Message& m)
  66. em System.Windows.Forms.ButtonBase.WndProc(Message& m)
  67. em System.Windows.Forms.Button.WndProc(Message& m)
  68. em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  69. em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  70. em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  71. em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
  72. em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
  73. em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  74. em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  75. em System.Windows.Forms.Application.Run(Form mainForm)
  76. em ProjetoAlpha.Program.Main() em C:UserswilliansourcereposProjetoAlphaProjetoAlphaProgram.cs:linha 19
Add Comment
Please, Sign In to add comment