Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 November 20th, 2007, 03:24 PM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default CS1002: ; expected error

Hi!

Can someone tell me why I am getting ; expected error when I am trying to compile the following code.

I am trying to insert data from DataSet to Database table.
XML--->DataSet--->Database table

XML file:<CustomerList>
<Identification>
    <ID>1</ID>
    <Name>John </Name>
</Identification>
<Order>
<OrderNr>2</OrderNr>
<customerNr>100</customerNr>
<customerName>XXXX YYYYY</customerName>
</Order>
<Location>
<ID>1</ID>
<Place>NY</Place>
</Location>
<Identification>
    <ID>3</ID>
    <Name>Cameron </Name>
</Identification>
<Order>
<OrderNr>6</OrderNr>
<customerNr>300</customerNr>
<customerName>KKKK LLLL</customerName>
</Order>
<Location>
<ID>3</ID>
<Place>AR</Place>
</Location>
</CustomerList>

The code which gives me ;expected error:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">

void Page_Load(Object sender , EventArgs e)
{
        
DataSet ds;

ds = new DataSet();
ds.ReadXml( MapPath( "z.xml" ) );
SqlConnection conStr = new SqlConnection(System.Configuration.ConfigurationMa nager.AppSettings["dsn"]);
SqlCommand cmd = conStr.CreateCommand();

for (int i=0;i<ds.Tables[0].Rows.count;i++)
{
cmd.CommandText = "INSERT INTO testtbl(ID, OrderNr, Place) VALUES ('"+ds.Tables[0].Rows[i]["ID"].ToString()+"', ds.Tables[1].Rows[i]["OrderNr"].ToString(), ds.Tables[2].Rows[i]["Place"].ToString())"; //cmd.Parameters.Add("@ID",SqlDbType.varchar);
//cmd.Parameters.Add("@OrderNr",SqlDbType.varchar);
//cmd.Parameters.Add("@Place",SqlDbType.varchar);
constr.Open();
cmd.ExecuteNonQuery();
conStr.Close();

}

}



</Script>

<html>
<head><title>ReadOrder.aspx</title></head>
<body>
xxxxxxxxxxxxxxxxxxxxxxxx
</body>
</html>

There is already a ; at cmd.CommandText ...


Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1002: ; expected

Source Error:



for (int i=0;i<ds.Tables[0].Rows.count;i++)
{
cmd.CommandText = "INSERT INTO testtbl(ID, OrderNr, Place) VALUES (ds.Tables[0].Rows[i]["ID"].ToString(), ds.Tables[1].Rows[i]["OrderNr"].ToString(), ds.Tables[2].Rows[i]["Place"].ToString())" ;
//cmd.Parameters.Add("@ID",SqlDbType.varchar);
//cmd.Parameters.Add("@OrderNr",SqlDbType.varchar);
 
Old November 20th, 2007, 03:30 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Its fairly obvious isn't it?
this is what your whole SQL Statement breaks down to as far as the compiler is concerned:

"INSERT INTO testtbl(ID, OrderNr, Place) VALUES (ds.Tables[0].rows[i]["
ID
"].ToString(), ds.Tables[1].rows[i]["
OrderNr
"].ToString(), ds.Tables[2].rows[i]["Place"].ToString())" ;


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 20th, 2007, 03:30 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. lately I'm seeing a lot of error of the same kind around here.. you are not building a string, you are just throwing data into it hoping that the compiler understand what are you trying to do..

your command text should be:
Code:
cmd.CommandText = "INSERT INTO testtbl(ID, OrderNr, Place) VALUES " + (ds.Tables[0].rows[i]["ID"].ToString() + "," + ds.Tables[1].rows[i]["OrderNr"].ToString() & "," + ds.Tables[2].rows[i]["Place"].ToString() + ")" ;
also, what's the idea behind passing parameters to a command that will never use them???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 20th, 2007, 04:59 PM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey again!

your suggestion gives me the same error:
cmd.CommandText = "INSERT INTO testtbl(ID, OrderNr, Place) VALUES " + (ds.Tables[0].rows[i]["ID"].ToString() + "," + ds.Tables[1].rows[i]["OrderNr"].ToString() & "," + ds.Tables[2].rows[i]["Place"].ToString() + ")" ;

 
Old November 20th, 2007, 05:14 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I might suggest that you pick up a Beginning C# (or ASP.NET) book since it is obvious you are a beginner. Your error is occuring somewhere in this part of your string: VALUES " + (ds.Tables[0].rows[i]["ID"].ToString() + ","

(Yes I know where the error is at, but you aren't going to learn anything if I tell you.)

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 21st, 2007, 08:25 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Yep.. it has an error (I saw it now... but I think like Doug, you will have to find it, it's very easy)

and since you are a beginner, can you tell me why are you passing parameters to a query that doesn't used them?? or you don't know and just copy some code from somewhere???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 21st, 2007, 11:20 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry guys, If I have asked a stupied question. yes, there are som line of codes which I will never use them. Thre is nothing wrong with keeping them there as long as they do not give me errors, I may use them in the future.. Even, there were som errors in the for loop,intiallization, condtions, capital letters, ... This does not mean that this is my final code since I am testing the Syntax for my CommandText. Anyway, I have done it in my own way.

dparsons, have you written books. I want to buy them and read. you have posted 3150 in this forum and that does not make you Worlds Master. Don't undermine ppl. There are som ppl who think better than you. Think before you write unnecessary comments.
 
Old November 21st, 2007, 11:43 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

There is nothing wrong in keeping them.. but it could be very useful if you learn what that lines do and why are there..
and it makes your code look awful, if someone has to pick it up and change, and you have that lines that do nothing.. also keeping code that is dead makes software prone to be buggy

I will not defend Doug (he can do that by himself) but did you realize that your problem is how to concatenate a string, one of the first thing you try to learn when you pick up a new language??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 21st, 2007, 11:56 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is working nice. I am trying to improve it! Anyway thank you for reply.
belete

 
Old November 21st, 2007, 01:35 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First, no I have not authored any books for Wrox I am merely the person that validates the Technical Accuracy of a given book for the company. Authoring books and my level of expertise, however, is irrelevant to your post and I do not need to validate myself to you as my posts on the forum should speak for themselves.

I am curious, though, as to how you come to the conclusion that I am undermining you. Is it because I knew the anser to your problem and, instead of simply giving you the answer, I provided you a hint that forced you to think about the problem? Or is it because I suggested that you pick up a Beginners book?

I do no believe in spoon feeding people answers to their problems you are, after all, a programmer and deciphering compiler errors and being able to debug your own code should be second nature to you. In any event, if you are a beginner that is fine, post these types of questions in the beginners forum.

Lastly, from a "House Keeping" prespective it is unwise to simply have code in place that you "might" use at a later date. YOU understand what you are doing but the next programmer that comes along may get confused with all of the unecessary code.

hth.



================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========




Similar Threads
Thread Thread Starter Forum Replies Last Post
Object expected error hericles Javascript How-To 1 July 19th, 2007 10:21 AM
"Identifier expected" Error NehaJani VB.NET 2002/2003 Basics 6 January 23rd, 2006 11:27 PM
Error: Funtion expected lameneural Classic ASP Databases 4 December 6th, 2005 08:17 PM
Error: Function expected lameneural Java Basics 0 December 1st, 2005 06:57 AM
Error "Too Few Parameters - Expected 1" timmaher Access VBA 2 August 31st, 2004 04:04 AM





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