problem with data reader..any expert here??

ss123

Member
Joined
Feb 25, 2006
Messages
14
Programming Experience
1-3
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
 
problem with showing data

Hi, if i want to use a input box that prompt user to key in the table name and show that data in data grid.
I have try this but can't work, so is there any alternatives?
i assign the value get from the input box to Myalue. Then i using the select query: select date, number from MyValue; i also try select date, number from '" & MyValue & "' .... both also can't work..
besides that, if i key in the table name without input box, it works but i cannot include open attribute but if i put * then all attribute can show include open attribute.
Anyone can advise me on this? the code is like below:
Dim myValue As String
' message = "Enter a stock name"
'title = "InputBox Demo"
'defaultValue = "Maxis"

'myValue = InputBox(message, title, defaultValue)
'If myValue Is "" Then
myValue = "Maxis"
OleAdapt = New OleDb.OleDbDataAdapter("Select * from '" & myValue & "'", ConOleDB)
OleAdapt.Fill(DsAllStock, "'" & myValue & "'")
DataGrid1.DataSource = DsAllStock.Tables("'" & myValue & "'")
DataGrid1.CaptionText = "Record No." & DataGrid1.CurrentRowIndex + 1 & " of 0" & DsAllStock.Tables("'" & myValue & "'").Rows.Count
 
Back
Top