DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 08 Aug 2007 14:37:01 +0100,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    DC
          2    Mark Fitzpatrick
          3    Damien
          4    DC


[Newbie Problem] BC30311: Value of "TableCell' cannot be converted to 'Integer'.   
Compiler Error Message: BC30311: Value of type 
'System.Web.UI.WebControls.TableCell' cannot be converted to 'Integer'. 
on line 63. while trying to write updates using a DataGrids Update method.

Source Error:

Line 61:
Line 62: 'Read in the values of the updated row
Line 63:     Dim ID as Integer = e.Item.Cells(0)
Line 64:      Dim strTitle as String = 
CType(e.Item.Cells(1).Controls(0), TextBox).Text
Line 65:      Dim strForeName as String = 
CType(e.Item.Cells(2).Controls(0), TextBox).Text

But If I use CType or CInt to convert the TableCell, I get the error...

BC30311: Value of type 'System.Web.UI.WebControls.TableCell' cannot be 
converted to 'Integer'.  for the line

Dim ID as Integer = CInt(e.Item.Cells(0))

I think I may have a basic conceptual problem with what is happening 
here. How does one get a cell from a DataTable in edit mode into an 
integer variable?

Here is the code.

Sub dgStaff_Update(sender As Object, e As DataGridCommandEventArgs)

'Read in the values of the updated row
	Dim intID as Integer = e.Item.Cells(0)
  	Dim strTitle as String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
  	Dim strForeName as String = CType(e.Item.Cells(2).Controls(0), 
TextBox).Text
  	Dim strSurName as String = CType(e.Item.Cells(3).Controls(0), 
TextBox).Text
  	Dim strRoomNo as String = CType(e.Item.Cells(4).Controls(0), 
TextBox).Text
  	Dim strPhoneNo as String = CType(e.Item.Cells(5).Controls(0), 
TextBox).Text
  	Dim strEmail as String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
  	Dim strStaff as String =  CType(e.Item.Cells(7).Controls(0), 
TextBox).Text
  	Dim strRole as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text


	'Construct the SQL statement using Parameters
  	Dim strSQL as String = _
       "UPDATE [user_table] SET [Title] = @Title, " & _
       "[ForeName] = @ForeName, [SurName] = @SurName " & _
	"[RoomNo] = @RoomNo, [PhoneNo] = @PhoneNo " & _
	"[EMail] = @EMail, [Staff] = @Staff " & _
	"[Role] = @Role " & _
       "WHERE [ID] = @ID"

	Const strConnString as String = _
	"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\Common 
Files\ODBC\Data Sources\user_info2.mdb"
	Dim objConn as New OleDbConnection(strConnString)
	objConn.Open()

	Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
	myCommand.CommandType = CommandType.Text

	' Add Parameters to the SQL query

	Dim parameterID as OleDbParameter = _
                new OleDbParameter("@ID", OleDbType.Integer)
	parameterID.Value = intID
	myCommand.Parameters.Add(parameterID)

	Dim parameterTitle as OleDbParameter = _
                new OleDbParameter("@Title", OleDbType.VarWChar, 75)
	parameterTitle.Value = strTitle
	myCommand.Parameters.Add(parameterTitle)

	Dim parameterForeName as OleDbParameter = _
                new OleDbParameter("@ForeName", OleDbType.VarWChar, 75)
	parameterForeName.Value = strForeName
	myCommand.Parameters.Add(parameterForeName)

	Dim parameterSurName as OleDbParameter = _
                new OleDbParameter("@SurName", OleDbType.VarWChar, 75)
	parameterSurName.Value = strSurName
	myCommand.Parameters.Add(parameterSurName)

	Dim parameterRoomNo as OleDbParameter = _
                new OleDbParameter("@RoomNo", OleDbType.VarWChar, 75)
	parameterRoomNo.Value = strRoomNo
	myCommand.Parameters.Add(parameterRoomNo)

	Dim parameterPhoneNo as OleDbParameter = _
                new OleDbParameter("@PhoneNo", OleDbType.VarWChar, 75)
	parameterPhoneNo.Value = strPhoneNo
	myCommand.Parameters.Add(parameterPhoneNo)

	Dim parameterEMail as OleDbParameter = _
                new OleDbParameter("@EMail", OleDbType.VarWChar, 75)
	parameterEMail.Value = strEMail
	myCommand.Parameters.Add(parameterEMail)

	Dim parameterStaff as OleDbParameter = _
                new OleDbParameter("@Staff", OleDbType.Boolean, 75)
	parameterStaff.Value =  Convert.ToBoolean(strStaff)
	myCommand.Parameters.Add(parameterStaff)

	Dim parameterRole as OleDbParameter = _
                new OleDbParameter("@Role", OleDbType.VarWChar, 75)
	parameterRole.Value =  strRole
	myCommand.Parameters.Add(parameterRole)

	myCommand.ExecuteNonQuery()   'Execute the UPDATE query

	objConn.Close()   'Close the connection


	'Finally, set the EditItemIndex to -1 and rebind the DataGrid
	dgStaff.EditItemIndex = -1
	BindData()
End Sub
Date:Wed, 08 Aug 2007 14:37:01 +0100   Author:  

Re: [Newbie Problem] BC30311: Value of "TableCell' cannot be converted to 'Integer'.   
What are you trying to get at?

Dim ID as Integer = CInt(e.Item.Cells(0)) cannot work!

Remember, that you are accessing a Cells collection. e.Item.Cells(0) simply 
gets you a copy of the TableCell control. You can't turn a cell into an 
integer. Think of it like this, a table cell renders into a <td></td>. 
That's not exactly the behavior here, but you can't turn a non-integer 
object into an integer. Can you explain a bit better what you are attempting 
to do with this value?

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage


"DC"  wrote in message 
news:f9cgtt$k5u$1@south.jnrs.ja.net...

>  Compiler Error Message: BC30311: Value of type 
> 'System.Web.UI.WebControls.TableCell' cannot be converted to 'Integer'. on 
> line 63. while trying to write updates using a DataGrids Update method.
>
> Source Error:
>
> Line 61:
> Line 62: 'Read in the values of the updated row
> Line 63:     Dim ID as Integer = e.Item.Cells(0)
> Line 64:      Dim strTitle as String = CType(e.Item.Cells(1).Controls(0), 
> TextBox).Text
> Line 65:      Dim strForeName as String = 
> CType(e.Item.Cells(2).Controls(0), TextBox).Text
>
> But If I use CType or CInt to convert the TableCell, I get the error...
>
> BC30311: Value of type 'System.Web.UI.WebControls.TableCell' cannot be 
> converted to 'Integer'.  for the line
>
> Dim ID as Integer = CInt(e.Item.Cells(0))
>
> I think I may have a basic conceptual problem with what is happening here. 
> How does one get a cell from a DataTable in edit mode into an integer 
> variable?
>
> Here is the code.
>
> Sub dgStaff_Update(sender As Object, e As DataGridCommandEventArgs)
>
> 'Read in the values of the updated row
> Dim intID as Integer = e.Item.Cells(0)
>  Dim strTitle as String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
>  Dim strForeName as String = CType(e.Item.Cells(2).Controls(0), 
> TextBox).Text
>  Dim strSurName as String = CType(e.Item.Cells(3).Controls(0), 
> TextBox).Text
>  Dim strRoomNo as String = CType(e.Item.Cells(4).Controls(0), 
> TextBox).Text
>  Dim strPhoneNo as String = CType(e.Item.Cells(5).Controls(0), 
> TextBox).Text
>  Dim strEmail as String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
>  Dim strStaff as String =  CType(e.Item.Cells(7).Controls(0), 
> TextBox).Text
>  Dim strRole as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text
>
>
> 'Construct the SQL statement using Parameters
>  Dim strSQL as String = _
>       "UPDATE [user_table] SET [Title] = @Title, " & _
>       "[ForeName] = @ForeName, [SurName] = @SurName " & _
> "[RoomNo] = @RoomNo, [PhoneNo] = @PhoneNo " & _
> "[EMail] = @EMail, [Staff] = @Staff " & _
> "[Role] = @Role " & _
>       "WHERE [ID] = @ID"
>
> Const strConnString as String = _
> "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\Common 
> Files\ODBC\Data Sources\user_info2.mdb"
> Dim objConn as New OleDbConnection(strConnString)
> objConn.Open()
>
> Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
> myCommand.CommandType = CommandType.Text
>
> ' Add Parameters to the SQL query
>
> Dim parameterID as OleDbParameter = _
>                new OleDbParameter("@ID", OleDbType.Integer)
> parameterID.Value = intID
> myCommand.Parameters.Add(parameterID)
>
> Dim parameterTitle as OleDbParameter = _
>                new OleDbParameter("@Title", OleDbType.VarWChar, 75)
> parameterTitle.Value = strTitle
> myCommand.Parameters.Add(parameterTitle)
>
> Dim parameterForeName as OleDbParameter = _
>                new OleDbParameter("@ForeName", OleDbType.VarWChar, 75)
> parameterForeName.Value = strForeName
> myCommand.Parameters.Add(parameterForeName)
>
> Dim parameterSurName as OleDbParameter = _
>                new OleDbParameter("@SurName", OleDbType.VarWChar, 75)
> parameterSurName.Value = strSurName
> myCommand.Parameters.Add(parameterSurName)
>
> Dim parameterRoomNo as OleDbParameter = _
>                new OleDbParameter("@RoomNo", OleDbType.VarWChar, 75)
> parameterRoomNo.Value = strRoomNo
> myCommand.Parameters.Add(parameterRoomNo)
>
> Dim parameterPhoneNo as OleDbParameter = _
>                new OleDbParameter("@PhoneNo", OleDbType.VarWChar, 75)
> parameterPhoneNo.Value = strPhoneNo
> myCommand.Parameters.Add(parameterPhoneNo)
>
> Dim parameterEMail as OleDbParameter = _
>                new OleDbParameter("@EMail", OleDbType.VarWChar, 75)
> parameterEMail.Value = strEMail
> myCommand.Parameters.Add(parameterEMail)
>
> Dim parameterStaff as OleDbParameter = _
>                new OleDbParameter("@Staff", OleDbType.Boolean, 75)
> parameterStaff.Value =  Convert.ToBoolean(strStaff)
> myCommand.Parameters.Add(parameterStaff)
>
> Dim parameterRole as OleDbParameter = _
>                new OleDbParameter("@Role", OleDbType.VarWChar, 75)
> parameterRole.Value =  strRole
> myCommand.Parameters.Add(parameterRole)
>
> myCommand.ExecuteNonQuery()   'Execute the UPDATE query
>
> objConn.Close()   'Close the connection
>
>
> 'Finally, set the EditItemIndex to -1 and rebind the DataGrid
> dgStaff.EditItemIndex = -1
> BindData()
> End Sub 
Date:Wed, 8 Aug 2007 08:51:00 -0500   Author:  

Re: BC30311: Value of "TableCell' cannot be converted to 'Integer'.   
On Aug 8, 2:37 pm, DC  wrote:

>   Compiler Error Message: BC30311: Value of type
> 'System.Web.UI.WebControls.TableCell' cannot be converted to 'Integer'.
> on line 63. while trying to write updates using a DataGrids Update method.
>
> Source Error:
>
> Line 61:
> Line 62: 'Read in the values of the updated row
> Line 63:     Dim ID as Integer = e.Item.Cells(0)
> Line 64:      Dim strTitle as String =
> CType(e.Item.Cells(1).Controls(0), TextBox).Text
> Line 65:      Dim strForeName as String =
> CType(e.Item.Cells(2).Controls(0), TextBox).Text
>
> But If I use CType or CInt to convert the TableCell, I get the error...
>
> BC30311: Value of type 'System.Web.UI.WebControls.TableCell' cannot be
> converted to 'Integer'.  for the line
>
> Dim ID as Integer = CInt(e.Item.Cells(0))
>
> I think I may have a basic conceptual problem with what is happening
> here. How does one get a cell from a DataTable in edit mode into an
> integer variable?
>

e.Item.Cells(0) should be e.Item.Cells(0).Text

the object returned by e.Item.Cells(0) is a TableCell - a rich object
that can have it's font, colour, style, etc read or changed. What
you're wanting to deal with is the *content* of the cell, which is
returned by the Text property.

Damien
Date:Wed, 08 Aug 2007 06:53:11 -0700   Author:  

Re: BC30311: Value of "TableCell' cannot be converted to 'Integer'.   

> e.Item.Cells(0) should be e.Item.Cells(0).Text
> 
> the object returned by e.Item.Cells(0) is a TableCell - a rich object
> that can have it's font, colour, style, etc read or changed. What
> you're wanting to deal with is the *content* of the cell, which is
> returned by the Text property.
> 
> Damien


Great Damien thanks a lot. I think it will take a while for me to get my 
head round the objects in .net :D

Luck,
Date:Wed, 08 Aug 2007 17:11:35 +0100   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us