Showing posts with label items. Show all posts
Showing posts with label items. Show all posts

Monday, March 26, 2012

Incorrect syntax near Items

Hi,

I am getting a mysterious error message, and it doesnt say which line it referres to, just gives me a stack trace.

Could somone decipher it for me?:

System.Data.SqlClient.SqlException: Incorrect syntax near 'items'.

[SqlException (0x80131904): Incorrect syntax near 'items'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +180
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +68
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2411
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +190
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +380
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +115
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +395
System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +405
System.Web.UI.WebControls.SqlDataSource.Insert() +13
detailproview.Button2_Command(Object sender, CommandEventArgs e) +41
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4886
 
My page code is:
private bool ExecuteUpdate(int quantity)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Integrated Security=True;User Instance=True";

con.Open();

SqlCommand command = new SqlCommand();
command.Connection = con;
TextBox TextBox1 = (TextBox)FormView1.FindControl("TextBox1");
Label labname = (Label)FormView1.FindControl("Label3");
Label labid = (Label)FormView1.FindControl("Label13");

command.CommandText = "UPDATE Items SET Quantityavailable = @.qty WHERE productID=@.productID";
command.Parameters.Add("@.qty", TextBox1.Text);
command.Parameters.Add("@.productID", labid.Text);
command.ExecuteNonQuery();

con.Close();
return true;
}

private bool ExecuteInsert(String quantity)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Integrated Security=True;User Instance=True";

con.Open();

SqlCommand command = new SqlCommand();
command.Connection = con;
TextBox TextBox1 = (TextBox)FormView1.FindControl("TextBox1");
Label labname = (Label)FormView1.FindControl("Label3");
Label labid = (Label)FormView1.FindControl("Label13");

command.CommandText = "INSERT INTO Transactions (Usersname)VALUES (@.User)"+
"INSERT INTO Transactions (Itemid)VALUES (@.productID)"+
"INSERT INTO Transactions (itemname)VALUES (@.Itemsname)"+
"INSERT INTO Transactions (Date)VALUES (+DateTime.Now.ToString() +)"+
"INSERT INTO Transactions (Qty)VALUES (@.qty)"+
command.Parameters.Add("@.User", System.Web.HttpContext.Current.User.Identity.Name);
command.Parameters.Add("@.Itemsname", labname.Text);
command.Parameters.Add("@.productID", labid.Text);
command.Parameters.Add("@.qty", TextBox1.Text);
command.ExecuteNonQuery();

con.Close();
return true;
}

protected void Button2_Click(object sender, EventArgs e)
{
TextBox TextBox1 = FormView1.FindControl("TextBox1") as TextBox;
ExecuteUpdate(Int32.Parse(TextBox1.Text) );
}

protected void Button2_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Update")
{
SqlDataSource1.Insert();
}
}
}.

 
 
Thanks!
Jon 

The error is referring to the SQL syntax you are using in your queries. There is a line in your stack trace that reads "System.Web.UI.WebControls.SqlDataSource.Insert() +13" which tends to suggest that the problem is in your INSERT statement, although looking at your INSERT statement I cannot see where "items" is mentioned. One bit that does confuse me is your Button2_Comand event-hander: why do you checke.CommandName == "Update" and then callSqlDataSource1.Insert() ?

Hope this helps

|||

Hi,

I cant see where items is mentioned either..

I checked update because the buttons command name is update, but I also want it to insert.. (it both updates and inserts).

Where else could the items error be happening??

Thanks,

Jon

|||

I have just noticed that you haveExecuteUpdateandExecuteInsertmethods defined in your code, but you are calling the Insert method of theSqlDataSource1control: what SQL statements have you got defined against SqlDataSource1?

|||

Well the data is on a formview which is attached so Sqdatasource1..

Perhaps I should try to called insert method of execute insert - how would I write this?:

if (e.CommandName == "Update")
{
ExecuteInsert.Insert();

?

Thanks!

Jon

|||You should just be able to write this:
if (e.CommandName =="Update") { ExecuteInsert();}
|||

Hi,

I tried that but got the error:

No overload for method 'ExecuteInsert' takes '0' arguments

Line 86: ExecuteInsert();
??
Thanks,
Jon 

|||

Ah, sorry, I didn't notice that yourExecuteInsertrequired a quantity parameter: just pass the method the quantity you require to be inserted.

Wednesday, March 21, 2012

Incorrect page count on reports that use drill-down or have hidden

I am getting an incorrect page count on reports that use drill-down or where
report items are hidden. The Globals!TotalPages returns 1 on a report that
clearly has more than one page. On these reports, the Globals!TotalPages
returns the correct page count for the print preview. I get the same results
whether this function is in the header or footer. My goal is to display the
current page and total pages on each page.
If I remove the expression from the Hidden property I get the correct page
count.
I am using SQL 2005 and Reporting Services 2005.Hello mrScott,
Based on my test, the TotalPages will return correct result in my side when
never I use the hidden report item or drill down report.
Would you please send the report to me so that I can try to reproduce it on
my side? You could create a simple report based on the Sample database in
SQL 2005.
To reach me, please remove the ONLINE in my email address.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================(This posting is provided "AS IS", with no warranties, and confers no
rights.)|||Hello Scott,
I have tested on my side.
I think that you misunderstood this problem.
The pagecount you see in the preview is page count for the HTML layout.
When you click the Print Layout, since it will re pagenate the report
according to the page setting, you will get another page count.
If you zoom in the print preview in the Print Layout, you could see the
Pagecount in the up-right is 9.
This is the correct behavior.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hello Scott,
I have tested on my side.
I think that you misunderstood this problem.
The pagecount you see in the preview is page count for the HTML layout.
When you click the Print Layout, since it will re pagenate the report
according to the page setting, you will get another page count.
If you zoom in the print preview in the Print Layout, you could see the
Pagecount in the up-right is 9.
This is the correct behavior.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Wei Lu,
If I understand you correctly, Globals!TotalPages returns one value for the
HTML layout and can return a different value for the Print Layout? Even
though the InteractiveSize and the PageSize are the same?
Is it possible to display Globals!TotalPages only for the Print Layout? Is
there a property or global variable that indicates whether the report is in
HTML or Print Layout? I don't need to display the page count for the HTML
layout but would like to display it when the report is printed.
Thanks again for you assistance.
"Wei Lu [MSFT]" wrote:
> Hi ,
> How is everything going? Please feel free to let me know if you need any
> assistance.
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================> This posting is provided "AS IS" with no warranties, and confers no rights.
>|||Hello Scott,
When you print the report, the Globals!TotalPages will return the value for
the print layout.
You could ignore it when you get the HTML layout.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================(This posting is provided "AS IS", with no warranties, and confers no
rights.)|||Wei Lu,
You were right in your second response to me, I misunderstood the problem.
The sections "Controlling Report Pagination" and " Understanding Report
Layout and Rendering" in " SQL Server 2005 Books Online" drove it home.
Since I can't get the page count to match in both layouts, ignoring it in
the HTML layout is the solution. I set the InteractiveSize Height to zero so
that the page count will always be one when the report is in the HTML layout
and greater than one in print layout. I can then hide the textbox containing
the page count in the HTML layout and show it in the print layout. If you
have a better idea for ignoring the page count in the HTML layout please let
me know.
Thanks again.
"Wei Lu [MSFT]" wrote:
> Hello Scott,
> When you print the report, the Globals!TotalPages will return the value for
> the print layout.
> You could ignore it when you get the HTML layout.
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>|||Hello Scott,
For now I think ignorint the page count in the HTML layout is the only
thing you could do.
You could send your feedback to the product team if you have any concern.
http://connect.microsoft.com/sqlserver
Hope this will be helpful.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.

Friday, February 24, 2012

IN() operator problem

i have a list of ID's (indexed) more than 2500 items.
first i have to select these records from one and then Update in
another table. when i pass the list to sql with IN() operator in
select query it takes too long (about 2 mins) and when i run update
query with same criteria it takes too much time.
i am using VB6 for development.
the field is indexed.

what i should do to improve performance?

Khurram Rao[posted and mailed, please reply in news]

Khurram (khurramanis@.gmail.com) writes:
> i have a list of ID's (indexed) more than 2500 items.
> first i have to select these records from one and then Update in
> another table. when i pass the list to sql with IN() operator in
> select query it takes too long (about 2 mins) and when i run update
> query with same criteria it takes too much time.
> i am using VB6 for development.
> the field is indexed.

Yes, the IN operator with many elements performs badly.

This article discusses different alternatives:
http://www.sommarskog.se/arrays-in-sql.html.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||>> I have a list of ID's (indexed) more than 2500 items. First I have
to select these records [sic] from one and then Update in another
table. When I pass the list to SQL with IN() operator in select query
it takes too long (about 2 mins) and when I run update query with same
criteria it takes too much time.

Rows are not like records at all. Please post your code and DDL.
You are describing procedural steps, not a relational approach.|||um - create a temp table with your list, and join to it in the update
statement?

"Khurram" <khurramanis@.gmail.com> wrote in message
news:60ff3d6c.0412040236.6e0466ea@.posting.google.c om...
>i have a list of ID's (indexed) more than 2500 items.
> first i have to select these records from one and then Update in
> another table. when i pass the list to sql with IN() operator in
> select query it takes too long (about 2 mins) and when i run update
> query with same criteria it takes too much time.
> i am using VB6 for development.
> the field is indexed.
> what i should do to improve performance?
> Khurram Rao