USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  VB.NET - Erro ao gravar no banco ACCESS
Léo951
RIO DE JANEIRO
RJ - BRASIL
ENUNCIADA !
Postada em 27/04/2006 00:30 hs            

Imports System.Data

Imports System.Data.OleDb

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 214)

Me.Name = "Form1"

Me.Text = "Form1"

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim conn As New OleDbConnection

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:     este.mdb"

Dim cmd As OleDbCommand = conn.CreateCommand

cmd.CommandText = "insert into Clientes (Nome) value (Leonardo,'Nome')"

conn.Open()

cmd.ExecuteNonQuery()

conn.Close()

MsgBox("Registro incluido")

End Sub

End Class

 

dá um erro assim: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

Alguém tem algum palpite?

   
Sidnei X-Crow
Pontos: 2843
VITÓRIA
ES - BRASIL
ENUNCIADA !
Postada em 29/04/2006 10:00 hs         
Bem primeiro a sql está errada, e seguindo o padrão ansi... deveria ficar assim:
"insert into Clientes (Nome) values ('Leonardo')

segundo:

Sempre use try... catch... assim vc pode dar um dum na exception e ver a descrição do erro bonitinha

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
try
Dim conn As New OleDbConnection

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:     este.mdb"

Dim cmd As OleDbCommand = conn.CreateCommand

cmd.CommandText = "insert into Clientes (Nome) value (Leonardo,'Nome')"

conn.Open()

cmd.ExecuteNonQuery()

conn.Close()

MsgBox("Registro incluido")
catch ex as Exception
   throw ex
End Sub
   
Página(s): 1/1    


Seu Nome:

Seu eMail:

ALTERAR PARA MODO HTML
Mensagem:

[:)] = 
[:P] = 
[:(] = 
[;)] = 

HTML DESLIGADO

     
 VOLTAR

  



CyberWEB Network Ltda.    © Copyright 2000-2025   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página