i have written a query that calculate and retrieve the data from access db but it show the data reader got problem. I use back the same query in access db but it works, can anyone help? Please advise. Thank you.
below is the program.. i already highlighted the area..
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing.Printing
Imports System.IO
Public Class bar
Inherits System.Windows.Forms.Form
Private Sub bar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Dim myConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "DATA SOURCE=C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WinStock\AllStocks.mdb;User Id='admin';Password='';")
'"DATA SOURCE=C:\Documents and Settings\Administrator\My Documents\Plantation.mdb;User Id='admin';Password='';")
Dim myConnection1 As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"DATA SOURCE=C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WinStock\KLSE.mdb;User Id='admin';Password='';")
'Dim mySelectQuery As String = "SELECT Date,Last FROM digi"
'Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
'myConnection.Open()
'Dim myReader As OleDbDataReader
'myReader = myCommand.ExecuteReader()
',Round([Price]/[EPS],2),Round([Dividend]/[Price],2)
'Dim mySelectQuery1 As String = "SELECT Round([Equity]/[Number_of_share],2) FROM Stock WHERE Code=6947"
Dim mySelectQuery1 As String = "SELECT Round([Equity]/[Number_of_share],2)FROM Stock WHERE Code=6947"
Dim myCommand1 As New OleDbCommand(mySelectQuery1, myConnection1)
myConnection1.Open()
Dim myReader1 As OleDbDataReader
myReader1 = myCommand1.ExecuteReader()
Dim junk As ZedGraph.ZedGraphControl
junk = zgc
junk.GraphPane.Title = "Test Case for VB"
junk.IsShowPointValues = True
Dim i As Integer
Dim x As Double, y As Double
Dim ppl As New ZedGraph.PointPairList
For i = 0 To 259
'myReader.Read()
'x = (myReader.GetDateTime(0)).ToOADate
'y = myReader.GetDouble(1)
'ppl.Add(x, y)
Next
Dim nta As Double
Dim per As Double
Dim dy As Double
For i = 0 To 1
myReader1.Read()
nta = myReader1.GetDouble(0)
'per = myReader1.GetDouble(1)
'dy = myReader1.GetDouble(2)
Next
'txtdy.Text = dy
'txtper.Text = per
txtnta.Text = nta
junk.GraphPane.XAxis.Type = ZedGraph.AxisType.Date
'junk.GraphPane.AddBar("aaa", ppl, Color.Blue)
'junk.GraphPane.AddCurve("Sine Wave", ppl, Color.Blue, ZedGraph.SymbolType.Diamond)
junk.GraphPane.AxisFill = New ZedGraph.Fill(Color.White, Color.LightGoldenrodYellow)
junk.GraphPane.XAxis.MinorUnit = ZedGraph.DateUnit.Month
junk.GraphPane.XAxis.MajorUnit = ZedGraph.DateUnit.Month
junk.GraphPane.XAxis.Step = 2
junk.GraphPane.XAxis.ScaleFormat = "MMM - yy"
junk.AxisChange()
'myReader.Close()
'myConnection.Close()
myReader1.Close()
myConnection1.Close()
End Sub
End Class
below is the program.. i already highlighted the area..
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing.Printing
Imports System.IO
Public Class bar
Inherits System.Windows.Forms.Form
Private Sub bar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Dim myConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "DATA SOURCE=C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WinStock\AllStocks.mdb;User Id='admin';Password='';")
'"DATA SOURCE=C:\Documents and Settings\Administrator\My Documents\Plantation.mdb;User Id='admin';Password='';")
Dim myConnection1 As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"DATA SOURCE=C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WinStock\KLSE.mdb;User Id='admin';Password='';")
'Dim mySelectQuery As String = "SELECT Date,Last FROM digi"
'Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
'myConnection.Open()
'Dim myReader As OleDbDataReader
'myReader = myCommand.ExecuteReader()
',Round([Price]/[EPS],2),Round([Dividend]/[Price],2)
'Dim mySelectQuery1 As String = "SELECT Round([Equity]/[Number_of_share],2) FROM Stock WHERE Code=6947"
Dim mySelectQuery1 As String = "SELECT Round([Equity]/[Number_of_share],2)FROM Stock WHERE Code=6947"
Dim myCommand1 As New OleDbCommand(mySelectQuery1, myConnection1)
myConnection1.Open()
Dim myReader1 As OleDbDataReader
myReader1 = myCommand1.ExecuteReader()
Dim junk As ZedGraph.ZedGraphControl
junk = zgc
junk.GraphPane.Title = "Test Case for VB"
junk.IsShowPointValues = True
Dim i As Integer
Dim x As Double, y As Double
Dim ppl As New ZedGraph.PointPairList
For i = 0 To 259
'myReader.Read()
'x = (myReader.GetDateTime(0)).ToOADate
'y = myReader.GetDouble(1)
'ppl.Add(x, y)
Next
Dim nta As Double
Dim per As Double
Dim dy As Double
For i = 0 To 1
myReader1.Read()
nta = myReader1.GetDouble(0)
'per = myReader1.GetDouble(1)
'dy = myReader1.GetDouble(2)
Next
'txtdy.Text = dy
'txtper.Text = per
txtnta.Text = nta
junk.GraphPane.XAxis.Type = ZedGraph.AxisType.Date
'junk.GraphPane.AddBar("aaa", ppl, Color.Blue)
'junk.GraphPane.AddCurve("Sine Wave", ppl, Color.Blue, ZedGraph.SymbolType.Diamond)
junk.GraphPane.AxisFill = New ZedGraph.Fill(Color.White, Color.LightGoldenrodYellow)
junk.GraphPane.XAxis.MinorUnit = ZedGraph.DateUnit.Month
junk.GraphPane.XAxis.MajorUnit = ZedGraph.DateUnit.Month
junk.GraphPane.XAxis.Step = 2
junk.GraphPane.XAxis.ScaleFormat = "MMM - yy"
junk.AxisChange()
'myReader.Close()
'myConnection.Close()
myReader1.Close()
myConnection1.Close()
End Sub
End Class