Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specified cast is not valid 1

Status
Not open for further replies.
Mar 14, 2002
711
US
I keep seeing this error from this code, the query does work in the database and it does display data, but when I run this in ASP.net, I get the error...

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

Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Quality Metrics Database.mdb"

Dim conMetrics As OleDbConnection = New OleDbConnection(connectString)

conMetrics.Open()

Dim cmdSelect1 = New OleDbCommand("SELECT DISTINCT [All Plants Summary Data].Plant FROM [All Plants Summary Data] order by Plant", conMetrics)

Dim PlantDL As OleDbDataReader()

PlantDL = cmdSelect1.ExecuteReader()

If Not IsPostBack Then
Plant.DataSource = PlantDL
Plant.DataValueField = "PLANT"
Plant.DataTextField = "PLANT"
Plant.DataBind()
Plant.Items.Insert(0, New ListItem("Select Plant"))
conMetrics.Close()

End If

Dim strPlant
strPlant = Plant.SelectedItem.Value

End Sub
 
PlantDL = cmdSelect1.ExecuteReader()

Which to me would indicate an error with the query...?
 
I'm not too familiar with data readers. I belive you have to loop through the reader to assign the values? Anyway, check the definition of the reader columns to the datatype of the columns being returned. There must be a datatype mismatch somewhere.

 
This is silly, but all it was:

Dim PlantDL As OleDbDataReader()

Was changed to:

Dim PlantDL As OleDbDataReader

And then it worked? Oh well...hehehehe, thanks for your attention to the Datareader Jbenson, that's where the issue was..
 
but i am confused! () is also a valid way to initialise an object of a class!!!

Known is handfull, Unknown is worldfull
 
it makes me do this :p. ;)

Known is handfull, Unknown is worldfull
 
I hear ya both, but that is what it complained about, everything else was fine in the code...I have never ever seen anything like it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top