Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2007, 10:12 AM
Authorized User
 
Join Date: Jun 2007
Location: hyderabad, AndhraPradesh, India.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query on Chat server?

Hi there, I started wrox chat server last night. Everything is working fine. Except this part. It says cannot convert string to int.Please check this

if (!IsPostBack )
        {

            DataSet dsChatRooms;
            dsChatRooms = ChatRoom.GetChatRoomList();
            DataTable dtChatRoom;
            int currentRow = 0;
            dtChatRoom = dsChatRooms.Tables[0];
            //DataRow drChatRoom;
            int lastCategoryID = 0;


            foreach (DataRow drChatRoom in dtChatRoom.Rows)
            {

 int CategoryId = dtChatRoom.Rows[currentRow].ItemArray["CatID"].ToString();
 String CategoryName = dtChatRoom.Rows[currentRow].ItemArray["CatName"].ToString();
 int RoomId = dtChatRoom.Rows[currentRow].ItemArray["RoomID"].ToString();
String RoomName = dtChatRoom.Rows[currentRow].ItemArray["RoomName"].ToString();

                if (CategoryId != lastCategoryID)
                {

                  TreeView1.Nodes.Add(new TreeNode(CategoryName, CategoryId.ToString()));
                }
                currentRow = currentRow + 1;
                lastCategoryID = CategoryId;
            }
            currentRow = 0;

            foreach (TreeNode mNode in TreeView1.Nodes)
            {

                foreach ( DataRow drChatRoom in dtChatRoom.Select("CatID=" + mNode.Value))
                {
                    if (!drChatRoom.IsNull(0))
                    {
                        int RoomId = drChatRoom.ItemArray["RoomID"].ToString();
                        String RoomName =drChatRoom.ItemArray["RoomName"].ToString();

                        mNode.ChildNodes.Add(new TreeNode("<a href='chatroom.aspx?chatRoomID=" + RoomId.ToString() + "'>" + RoomName + "</a>", RoomId.ToString()));
                    }
                }
sorry for this long code.

regards,
Ossy!
__________________
Surya!
 
Old August 10th, 2007, 03:35 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Ossy,

And where (that is, on what line) do you get this error?

Did you type this code, or does it come from the download for the book?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 11th, 2007, 01:33 PM
Authorized User
 
Join Date: Jun 2007
Location: hyderabad, AndhraPradesh, India.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Imar,

I typed this code. The error is being generated in these lines

int CategoryId = dtChatRoom.Rows[currentRow].ItemArray["CatID"].ToString();
 String CategoryName = dtChatRoom.Rows[currentRow].ItemArray["CatName"].ToString();
 int RoomId = dtChatRoom.Rows[currentRow].ItemArray["RoomID"].ToString();
String RoomName = dtChatRoom.Rows[currentRow].ItemArray["RoomName"].ToString();
 
Old August 11th, 2007, 01:56 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Take a look at this:

int RoomId = dtChatRoom.Rows[currentRow].ItemArray["RoomID"].ToString();

You're calling ToString which results in a String which you're then assigning to an int. The compiler won't let you do this.

Instead, using (int) or Convert.ToInt32() to cast / convert a value to an integer.

How does the original source from the book look like?

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chat server - please help Nala C# 1 March 27th, 2007 12:10 AM
How to build Server Chat amorous_man Pro Java 1 January 2nd, 2007 09:51 AM
Chat Server Abend BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 June 19th, 2006 04:28 PM
Chat Server - Does not work mpremji BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 7 April 20th, 2006 11:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.