ExecuteNonQuery Wierdness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bug0926@yahoo.com

    #1

    ExecuteNonQuery Wierdness

    The following code runs and gets no errors...the select returns no
    rows, what am I doing wrong? I instantiate the class, run the write a
    few teams, then the read, and in vb.net I still see no data in the log
    table.

    Public Class cLog

    Enum eventType As Integer
    Ph = 1
    Temperature = 2
    ORP = 3
    Timer = 4
    Misc = 5
    End Enum

    Private dbConn As SqlClient.SqlCo nnection
    Private dbCommand As SqlClient.SqlCo mmand

    Public Sub New()

    dbConn = New
    SqlClient.SqlCo nnection(My.Set tings.DBConnect ionString)
    dbConn.Open()

    End Sub

    Public Sub Write(ByVal sensor As Integer, ByVal eventId As Integer,
    ByVal eventValue As String)
    Dim sql As String

    sql = "insert into Log (sensor, eventID, eventValue) values ("
    & sensor & "," & eventId & ",'" & eventValue & "')"

    dbCommand = dbConn.CreateCo mmand()
    dbCommand.Comma ndText = sql
    dbCommand.Execu teNonQuery()

    End Sub

    Public Sub read()
    Dim sql As String
    Dim dbReader As SqlClient.SqlDa taReader

    sql = "select timestamp, sensor, eventId, eventValue from Log"
    dbCommand = dbConn.CreateCo mmand()
    dbCommand.Comma ndText = sql

    dbReader = dbCommand.Execu teReader(sql)

    While dbReader.HasRow s
    Debug.Print(dbR eader(0))
    Debug.Print(dbR eader(1))

    End While
    dbReader.Close( )
    End Sub

    End Class

  • Kerry Moorman

    #2
    RE: ExecuteNonQuery Wierdness

    bug0926,

    While dbReader.Read( )

    Kerry Moorman


    "bug0926@yahoo. com" wrote:
    [color=blue]
    > The following code runs and gets no errors...the select returns no
    > rows, what am I doing wrong? I instantiate the class, run the write a
    > few teams, then the read, and in vb.net I still see no data in the log
    > table.
    >
    > Public Class cLog
    >
    > Enum eventType As Integer
    > Ph = 1
    > Temperature = 2
    > ORP = 3
    > Timer = 4
    > Misc = 5
    > End Enum
    >
    > Private dbConn As SqlClient.SqlCo nnection
    > Private dbCommand As SqlClient.SqlCo mmand
    >
    > Public Sub New()
    >
    > dbConn = New
    > SqlClient.SqlCo nnection(My.Set tings.DBConnect ionString)
    > dbConn.Open()
    >
    > End Sub
    >
    > Public Sub Write(ByVal sensor As Integer, ByVal eventId As Integer,
    > ByVal eventValue As String)
    > Dim sql As String
    >
    > sql = "insert into Log (sensor, eventID, eventValue) values ("
    > & sensor & "," & eventId & ",'" & eventValue & "')"
    >
    > dbCommand = dbConn.CreateCo mmand()
    > dbCommand.Comma ndText = sql
    > dbCommand.Execu teNonQuery()
    >
    > End Sub
    >
    > Public Sub read()
    > Dim sql As String
    > Dim dbReader As SqlClient.SqlDa taReader
    >
    > sql = "select timestamp, sensor, eventId, eventValue from Log"
    > dbCommand = dbConn.CreateCo mmand()
    > dbCommand.Comma ndText = sql
    >
    > dbReader = dbCommand.Execu teReader(sql)
    >
    > While dbReader.HasRow s
    > Debug.Print(dbR eader(0))
    > Debug.Print(dbR eader(1))
    >
    > End While
    > dbReader.Close( )
    > End Sub
    >
    > End Class
    >
    >[/color]

    Comment

    • GhostInAK

      #3
      Re: ExecuteNonQuery Wierdness

      Hello bug0926@yahoo.c om,

      The last part of your code is a lil screwy. Try this:

      Public Sub Read()

      Dim tSQL As String = "SELECT timestamp, sensor, eventId, eventValue FROM
      Log"
      Dim tConnection As SqlConnection = New SqlConnection
      Dim tCommand As SqlCommand = New SqlCommand
      Dim tReader As SqlDataReader = Nothing

      With tCommand
      .Connection = tConnection
      .COmmandType = CommandType.Tex t
      .CommandText = tSQL
      End With
      tConnection.Ope n
      tReader = tCommand.Execut eReader
      If tReader.HasRows Then
      While tReader.Read
      Debug.Print(Str ing.Format("{0} , {1}, {2}, {3}", tReader("timest amp"),
      tReader("sensor "), tReader("eventI d"), tReader("eventV alue")))
      End While
      End If
      tConnection.Clo se

      End Sub

      [color=blue]
      > Public Sub read()
      > Dim sql As String
      > Dim dbReader As SqlClient.SqlDa taReader
      > sql = "select timestamp, sensor, eventId, eventValue from Log"
      > dbCommand = dbConn.CreateCo mmand()
      > dbCommand.Comma ndText = sql
      > dbReader = dbCommand.Execu teReader(sql)
      >
      > While dbReader.HasRow s
      > Debug.Print(dbR eader(0))
      > Debug.Print(dbR eader(1))
      > End While
      > dbReader.Close( )
      > End Sub[/color]


      Comment

      Working...