.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Help: SqlDataReader dr = command.ExecuteReader();

Posted By:      Posted Date: September 18, 2010    Points: 0   Category :Sql Server
Hi,   I downloaded the code of  this great article  "GridView with Thumbnail Images - Part 1" http://www.codedigest.com/Articles/ArticleFiles/ZIPS/102.zip   I have no problem uploading the images. but I have problem to load it intoGridView. The reason is : Incorrect syntax near '='. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '='.Source Error: Line 13: connection.Open(); Line 14: SqlCommand command = new SqlCommand("select Image from Image where ImageID="+imageid, connection); Line 15: SqlDataReader dr = command.ExecuteReader(); Line 16: dr.Read(); Line 17: context.Response.BinaryWrite((Byte[])dr[0]);   I am using sqlexpress. Table name is Image with columns ImageID(Identity), ImageName(Varchar(50)) and Image(image). Any help is appreciated.   Juvan   Here is the code;   <%@ WebHandler Language="C#" Class="FullImage" %> using System; using System.Web; using System.Data.SqlClient; using System.Configuration; public class FullImage : IHttpHandler { public void ProcessRequest (HttpContext context) { string imageid = context.Request.QueryString["ImID"

View Complete Post

More Related Resource Links

Row command working on all rows not selected one?



I have this code that hides a column in a gridview.  (The column houses another nested gridview).

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "Select" Then
            If GridView1.Columns(0).Visible = False Then
                GridView1.Columns(0).Visible = True
                GridView1.Columns(0).Visible = False
            End If
        End If
    End Sub

The trouble is that if I click the select link on one row that action to hide is carried out on all rows.  How can I set this up so that it only hides the row that is selected?


Print command



Is there a way of setting up a print area for a part of my webpage, I only want to print a certain part of the page, when I select print at the moment it will print the whole page and the layout is rubbish!!

command object error


Could someone please tell me what is wrong with my syntax here?  I'd be much appreciative.


objCmd = New SQLCommand("SELECT CASE WHEN objDR('Item') = 'Enter Bill of Lading' then enterbol " _  

& "WHEN objDR('Item') = 'Bill of Lading History' THEN bolhistory " _  

& "WHEN objDR('Item') = 'Request Transfer' or objDR('Item') = 'View Transfer in Progress' THEN transfers " _  

& "END  from plantGroups where plantgroupid=@plantgroupid", objConn)

sqlDataReader dos not get results


I am trying to run a stored proc from this function. When I run it thorugh the debugger I can see that myReader.HasRows = true and myReader.FieldCount =14.

But the control does not go in the loop while (myReader.Read()) where I am trying to read Version field returned by the stored proc.

Pls check me code and suggest correction. Thank You.

private static int Get_CaseInfo(string CaseNum)
            int Ver = 0;
            String myConn = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
            SqlConnection conn = new SqlConnection(myConn);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = System.Data.CommandType.Text;

            SqlDataReader myReader = null;
            String stmt1 = "EXEC [REPORTS].[CaseInfoByCaseNo_Get] @CaseNo = '" + CaseNum + "'"; 
            cmd.CommandText = stmt1;
            cmd.Connection = conn;
                myReader = cmd.ExecuteReader();
                while (myReader.Read())
                    Ver = (int)myReader["Version"];

            catch (Exception)
            return Ver;         

Design Patterns: Simplify Distributed System Design Using the Command Pattern, MSMQ, and .NET


Service-oriented architecture is a great framework when you need to perform distributed computing tasks over the Internet. But when you want to perform processing inside your local network, a different solution may provide a better fit. That solution, based on the Command pattern, uses Windows services and Microsoft Message Queuing to implement a queued system that meets your needs better than a service-oriented solution. This article explains how to build it.

Brad King

MSDN Magazine September 2004

Command Management: Use Design Patterns to Simplify the Relationship Between Menus and Form Elements


In Windows Forms applications, similar commands, such as those in a menu and their counterparts on a toolbar, are not automatically related. They don't fire the same event or run the same handler routine. Yet code that allows the same or similar user commands to fire the same code simplifies development.This article describes the principles of command management and why it's important to have functional commands that are not exclusive to any one UI element. In order to provide an MFC-like command management infrastructure, a design pattern is developed and applied as a series of C# classes.

Michael Foster and Gilberto Araya

MSDN Magazine October 2002

stsadm Import command + include user security



When I move sites from test to staging to production, I am using the stsadm –o export command with the –includeusersecurity option in the staging environment.  In production environment, I then use the stsadm –o import command with the –includeusersecurity option.  I was assuming that this option was bringing over the security on the exported site only.  This does not seem to be the case.

Last night I exported one sub site to produtction.  Today, I was notified that the security groups on other sub sites have been altered.  


So why is it when using the –includeusersecurity option effect all sub sites and not just the one sub site being moved from staging to production

Executing Command Logic in a View Model

Through the use of the Windows Presentation Foundation's (WPF) advanced data-binding capabilities, the logical structure of a user interface can relatively easily be disconnected from its presentation. Bindable components can now contain nearly all of an application's user interface logic and in most circumstances, replace the need for controller objects from the classic Model-View-Controller (MVC) pattern. So it's no wonder that a new pattern for UI design has appeared

There is already an open DataReader associated with this Command which must be closed first.


when i insert record

There is already an open DataReader associated with this Command which must be closed first.

help me.

SqlConnection conn = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=StudentDetails;Integrated Security=True");

SqlCommand cmd2 = new SqlCommand();
SqlCommand cmd1 = new SqlCommand();

if (conn.State == ConnectionState.Closed)

cmd2 = new SqlCommand("Select * from UserInfo where Standard", conn);
            SqlDataReader dr1 = cmd2.ExecuteReader();
            string stu, par,std,sec,roll;
            par = "";
            stu = "";
            std = "";

Query Command to Report


I would like to generate a crystal report showing the report data based on my custom SQL query.

Where I can provide my SQL query or stored procedure.

Please give me good tutorial links on this too.

Thanks in advance.

Localization for command text Microsoft Ribbon for WPF

Hello, Is there any way I can localize the command text that comes with the ribbon, like the commands in the Ribbon context menu?   Add to Quick Access Toolbar Add gallery to Quick Access Toolbar Remove from Quick Access Toolbar Show Quick Access Toolbar above the Ribbon Show Quick Access Toolbar below the Ribbon Minimize the Ribbon Maximize the Ribbon   I got this list from the Source -- \Resources\ExceptionStringTable.txt

Command - Hyperlink

Why does the command work when I use it in a button, but not in the hyperlink? They are both bound the same way and named the same...             <Border Grid.Column="0" Width="170"                     Background="WhiteSmoke" BorderBrush="Lightgray" BorderThickness="1" CornerRadius="5" SnapsToDevicePixels="True">             <TreeView>                <TreeViewItem Header="Provinces">                   <Button Content="Show All Provinces" Command="{Binding Path=Command_ShowAllProvinces}" />                                     <Hyperlink Command="{Binding Path=Command_ShowAllProvinces}">                      <TextBlock T

Output parameters in OLEDB Command component - SSIS 2008

I have a package that I developed in SSIS 2005 and recently ported to 2008. Everything runs great except an OLE DB Command component that calls a stored procedure that uses output parameters. When I try to run this, I get this error: Error: 0xC0202009 at Data Flow Task, OLE DB Command [100]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Syntax error, permission violation, or other nonspecific error". Error: 0xC004701A at Data Flow Task, SSIS.Pipeline: component "OLE DB Command" (100) failed the pre-execute phase and returned error code 0xC0202009. When I do the same thing in SSIS2005, it works fine. So I setup a new package with 1 data flow. In that data flow, I added a source component, an OLE DB Command, and a destination.  I then tested this with a stored procedure that took no parameters. It worked fine. I then tested it with a stored procedure with 1 parameter defined as OUTPUT. This generated the error.   Is there an issue with output parameters in an OLE DB Command in SSIS 2008?   Thanks!http://bobp1339.blogspot.com

How to generate pdf from 2005 rdl report files from command prompt?

Hi All, I have a scenario like this, i have 10 rdl reports, which needs to run on a job basis with out any user interaction. Tell me is there any way to generate the pdf from command prompt using existing 2005 rdl files. Your help is more appreaciated!! Thanks, Sarvesh M  Sarvesh

How can I access Command Window in SSMS 2008

Hello, I'm debugging some t-sql code, I can view locals, watches etc. but I've closed command window by mistake and i couldn't find it again. Is there a shortcut key for this window? How I can access this window? Thanks in advance.

can't execute "create table" command with Visual Web Developer express

I have a folder with a web site I'm developing which is connected to a database.Every time I move the folder to a different computer it's a pain when I have to move the database and change the connection string.I've thought to use for the first time a database in the app_data folder and move all the database inside it.Nevertheless, when I try to recreate all the tables in the new database for the first time with the query "create table ..." I get and error saying that "SQL CREATE TABLE" is not supported.Is there a way to manage this situation?--   Giuseppe


Hi, I am migrating a code from ADO to ADO.NET. Here i am stuck with the SHAPE statement in sql query that is used in ADO. Please help me out with the equivalent code for ADO.NET   sql= " ((SHAPE { " + sql1+ " }  AS SECONDARY APPEND ";sql= sql+ " ({ " + sql2+ " } AS PROCEDURALSOURCE  RELATE 'STASKID' TO 'TASKID') AS PROCEDURALSOURCE, ";sql= sql+ " ({ " + sql3+ "  } AS TASKAREA RELATE 'STASKID' TO 'TASKID') AS TASKAREA, ";sql= sql+ " ({ " + sql4+ "  } AS REPEATS RELATE 'STASKID' TO 'STASKID') AS REPEATS, ";sql= sql+ " ({ " + sql5+ "  } AS SECONDARYUOM RELATE 'STASKID' TO 'TASKID') AS SECONDARYUOM)";sql= sql+ " AS SECONDARY RELATE 'TASKID' TO 'TASKID') AS SECONDARY";  where sql1, sql2, sql3, sql4, sql5 are complex select statements. It gives an invalid sql statement error in oracle db when i execute this. It would be great if some one helps me out with equivalent code in ado.net using datasets or some other thing. Thanks.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend