473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Error: Object must implement IConvertible

Hi can someone please help me with the following error!

I keep getting:

ERROR:
System.InvalidCastException: Object must implement IConvertible.

Line 231: PageID = cmd.Parameters("@PageID").Value
Line 232:
Line 233: Dim myReader As SqlDataReader = cmd.ExecuteReader()
Line 234: myReader.Read()
Line 235:

I would be really grateful if someone could tell me why this might be
happening!

Thanks

... CODE ..

Sub DGPages_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim modDate As String
Dim dtNow As DateTime = DateTime.Now
Dim description As String
Dim txtdescription As TextBox
Dim title As String
Dim txtTitle As TextBox
Dim PageID As Integer

Dim strSQL As String
modDate = dtNow.Date
'Read in the values of the TextBoxes
txtdescription = e.Item.FindControl("add_description")
description = txtdescription.Text
txtTitle = e.Item.FindControl("add_Title")
title = txtTitle.Text

'Create the appropriate SQL statement
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("PageAdd", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

' Add Parameters to the SQL query
Dim objModDate, objDescription, objTitle, objPageID, objOffice
As SqlParameter
objModDate = cmd.Parameters.Add("@modDate", SqlDbType.DateTime)
objDescription = cmd.Parameters.Add("@description",
SqlDbType.NVarChar)
objTitle = cmd.Parameters.Add("@title", SqlDbType.NVarChar)
objPageID = cmd.Parameters.Add("@PageID", SqlDbType.Int)

objModDate.Direction = ParameterDirection.Input
objDescription.Direction = ParameterDirection.Input
objTitle.Direction = ParameterDirection.Input
cmd.Parameters("@PageID").Direction = ParameterDirection.Output

objModDate.Value = modDate
objDescription.Value = txtdescription
objTitle.Value = txtTitle
PageID = cmd.Parameters("@PageID").Value

Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()

myReader.Close()

Myconn.Close()

'Rebind the DataGrid
DGPages.EditItemIndex = -1
BindData()
End If

End Sub
Nov 19 '05 #1
1 1794
Since your @PageID is an output parameter, you should put
PageID = cmd.Parameters("@PageID").Value after
any SqlCommand execute statement such as ExecuteNonQuery,
or ExecuteReader, or ExecuteScalar rather than before
those codes.

Hope it's helpful to you.

Elton
el********@hotmail.com

-----Original Message-----
Hi can someone please help me with the following error!

I keep getting:

ERROR:
System.InvalidCastException: Object must implement IConvertible.
Line 231: PageID = cmd.Parameters ("@PageID").ValueLine 232:
Line 233: Dim myReader As SqlDataReader = cmd.ExecuteReader()Line 234: myReader.Read()
Line 235:

I would be really grateful if someone could tell me why this might behappening!

Thanks

... CODE ..

Sub DGPages_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim modDate As String
Dim dtNow As DateTime = DateTime.Now
Dim description As String
Dim txtdescription As TextBox
Dim title As String
Dim txtTitle As TextBox
Dim PageID As Integer

Dim strSQL As String
modDate = dtNow.Date
'Read in the values of the TextBoxes
txtdescription = e.Item.FindControl ("add_description") description = txtdescription.Text
txtTitle = e.Item.FindControl("add_Title")
title = txtTitle.Text

'Create the appropriate SQL statement
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings ("strConn")) Dim cmd As New SqlCommand("PageAdd", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

' Add Parameters to the SQL query
Dim objModDate, objDescription, objTitle, objPageID, objOfficeAs SqlParameter
objModDate = cmd.Parameters.Add("@modDate", SqlDbType.DateTime) objDescription = cmd.Parameters.Add ("@description",SqlDbType.NVarChar)
objTitle = cmd.Parameters.Add("@title", SqlDbType.NVarChar) objPageID = cmd.Parameters.Add("@PageID", SqlDbType.Int)
objModDate.Direction = ParameterDirection.Input objDescription.Direction = ParameterDirection.Input objTitle.Direction = ParameterDirection.Input
cmd.Parameters("@PageID").Direction = ParameterDirection.Output
objModDate.Value = modDate
objDescription.Value = txtdescription
objTitle.Value = txtTitle
PageID = cmd.Parameters("@PageID").Value

Dim myReader As SqlDataReader = cmd.ExecuteReader() myReader.Read()

myReader.Close()

Myconn.Close()

'Rebind the DataGrid
DGPages.EditItemIndex = -1
BindData()
End If

End Sub
.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Leon Shaw | last post by:
Please help me understand this Error??? Server Error in '/solo' Application. ---------------------------------------------------------------------------- ---- Object must implement...
7
by: Leon Shaw | last post by:
Need help understanding? Server Error in '/solo' Application. ---------------------------------------------------------------------------- ---- Object must implement IConvertible....
5
by: Leon Shaw | last post by:
I'm trying to insert a record into a sql server 2000 database using a store procedure (vs.net is my develop tool) on the button click event but I keep getting the following error after clicking the...
1
by: George Durzi | last post by:
I want to convert a dataset to type object so I can pass it to a generalized function which accepts an object and adds it to the cache. If I pass it in like: Convert.ChangeType(MyDataSet,...
4
by: charleswesley | last post by:
I think the problem is with the strPrice variable in the AddToCart() sub. I've been messing with it all morning and can't seem to figure it out. Any ideas? ...
1
by: dan | last post by:
I am using VB.NET 2003 and SQL Server 2000. My program inserts new rows in a SQL table based on data read from a file. I generated the commands and the stored procedures with the DataAdapter...
3
by: dan | last post by:
I am using VB.NET 2003 and SQL Server 2000. My program inserts new rows in a SQL table based on data read from a file. I generated the commands and the stored procedures with the DataAdapter...
0
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error??? I can't seem to see what is causing the problem... Any help would be greatly appritiated! Thanks ...
0
by: dan | last post by:
Hi, I've been using a GridView for some time but this is the first time I need to delete a row in the grid whose primary key consists of 2 fields (table columns). I have a table with primary...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.