none
Erro Instrução SQL Insert - Não consigo Resolver! Helllp! RRS feed

  • Pergunta

  • Não consigo achar o erro nessa sub

     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim emitente As String
            Dim email_emitente As String
            Dim empresa As String
            Dim local1 As String
            Dim hora As String
            Dim descricao As String
            Dim sugestao As String
            Dim dt_registro As Date
            
            'emitente = DropDownList1.Text
            'email_emitente = TextBox1.Text
            'empresa = DropDownList2.Text
            'local = DropDownList3.Text
            'hora = DropDownList4.Text
            'descricao = TextBox2.Text
            'sugestao = TextBox3.Text
            'dt_registro = Calendar1.SelectedDate
            
            Dim MySQL As String = "INSERT INTO ocorrencias (emitente, email_emitente, empresa, local, hora, descricao, sugestao, dt_registro) VALUES (@emitente, @email_emitente, @empresa, @local1, @hora, @descricao, @sugestao, @dt_registro)"
            
            'Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Bibliotecas\Documentos\Visual Studio 2005\WebSites\iRos\App_Data\BD_ROS.mdb")
            Dim myConn As OleDbConnection = New OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
            
            Dim Cmd As New OleDbCommand(MySQL, myConn)
            
            Dim objDR As OleDbDataReader

            Cmd.Parameters.Add(New OleDbParameter("@emitente", DropDownList1.Text))
            Cmd.Parameters.Add(New OleDbParameter("@email_emitente", TextBox1.Text))
            Cmd.Parameters.Add(New OleDbParameter("@empresa", DropDownList2.Text))
            Cmd.Parameters.Add(New OleDbParameter("@local", DropDownList3.Text))
            Cmd.Parameters.Add(New OleDbParameter("@hora", DropDownList4.Text))
            Cmd.Parameters.Add(New OleDbParameter("@descricao", TextBox2.Text))
            Cmd.Parameters.Add(New OleDbParameter("@sugestao", TextBox3.Text))
            Cmd.Parameters.Add(New OleDbParameter("@dt_registro", Calendar1.SelectedDate.Date))


            myConn.Open()
            'Cmd.ExecuteNonQuery()
            
            objDR = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
            If objDR.Read() Then
                myConn.Close()
                MsgBox("ROS Cadastrado Com Sucesso", MsgBoxStyle.Information, "Informação Sistena iROS")
            End If
        End Sub

    quinta-feira, 4 de abril de 2013 19:57

Todas as Respostas

  • Poste o erro completo e em que linha o problema ocorre.

    Só o codigo nao ajuda muito.

    Att


    William John Adam Trindade
    Analyste-programmeur
    ----------------------------------------------------------

    Sogi informatique ltée


    quinta-feira, 4 de abril de 2013 20:18
    Moderador
  • System.Data.OleDb.OleDbException was unhandled by user code
      ErrorCode=-2147217900
      Message="Erro de sintaxe na instrução INSERT INTO."
      Source="Microsoft JET Database Engine"
      StackTrace:
           em System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
           em System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
           em System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
           em System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
           em System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
           em System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
           em ASP.default_aspx.Button1_Click(Object sender, EventArgs e) na d:\Bibliotecas\Documentos\Visual Studio 2005\WebSites\iRos\Default.aspx:linha 77
           em System.Web.UI.WebControls.Button.OnClick(EventArgs e)
           em System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
           em System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
           em System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
           em System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
           em System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    O erro dá na seguinte linha: 

    objDR = Cmd.ExecuteReader(CommandBehavior.CloseConnection)

    quinta-feira, 4 de abril de 2013 20:29