View Single Post
 
Old November 20th, 2007, 03:24 PM
belete belete is offline
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);