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

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

Can I pass a SqlParameterCollection object into a SQL Command

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net
I currently have a connection class that handles all of my database connectivity. What I am trying to do is build a SqlParameterCollection object on one page, then pass that object to my connection class. Is it possible to do this? I am not getting any compilation errors, but I can not get the parameters to be recognized. Here is what I am trying to do: Page 1: string sql = null; conn.strConn = connectionstring; sql = "sqlstring"; SqlParameterCollection newcollect = null; newcollect.Add("@Switch",1); conn.OpenReader(sql, newcollect); while (conn.DR.Read()) { read data onto page here... } conn.CloseReader(); Page 2 (connection class) : public void OpenReader(string sql, SqlParameterCollection collect) { Conn = new SqlConnection(strConn); Conn.Open(); Command = new SqlCommand(sql,Conn); Command.Parameters.Add(collect); <------This is the root of my question Command.CommandTimeout = 300; // executes sql and fills data reader with data DR = Command.ExecuteReader(); } Can you do this??? And if so, can anyone tell me why the statement will not return any data? The procedure works perfectly, and will work if I use the standard way of passing the parameters to the command statement.

View Complete Post

More Related Resource Links

Pass ASP.NET membership identity object across domain?


I am trying to figure a way to SSO with ASP.NET membership and role model.

I can implement custom membership provider which consume web services hosting on a server.

With encryption of data. No problem.

But my question is, If I sign on a website with my provider, got my identity object on that application,

could I pass it to another website on another domain which use the same provider and by doing so, do not need to login again?

If this is possible, I am going to implement this solution. Please tell me what's your take on this.

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)

Using a Variable in SSIS - Error - "Command text was not set for the command object.".

Hi All, i am using a OLE DB Source in my dataflow component and want to select rows from the source based on the Name I enter during execution time. I have created two variables, enterName - String packageLevel (will store the name I enter) myVar - String packageLevel. (to store the query) I am assigning this query to the myVar variable, "Select * from db.Users where (UsrName =  " + @[User::enterName] + " )" Now in the OLE Db source, I have selected as Sql Command from Variable, and I am getting the variable, enterName,. I select that and when I click on OK am getting this error.   Error at Data Flow Task [OLE DB Source [1]]: An OLE DB error has occurred. Error code: 0x80040E0C.An OLE DB record is available.  Source: "Microsoft SQL Native Client"  Hresult: 0x80040E0C  Description: "Command text was not set for the command object.". Can Someone guide me whr am going wrong? myVar variable, i have set the ExecuteAsExpression  Property to true too. Please let me know where am going wrong? Thanks in advance.

How to retrieve object that fired Command event.

Hi there, My situation is, I have a button that bind with a custom ICommand. When the button is clicked, the "CanExecute()" in the custom ICommand will be execute. The question is, how can I retrieve the button object inside "CanExecute()" ? Thanks. Regards, Rambo Ong

How to Pass a Grid an EF Object and have it edit/update etc. without postbacks until save?

Hey all.Here's what I'm trying to do:I want to pull an EF object, or create a new one. Pass it to javascript (jquery or some such) and then have the grid bind on the client side and do everything client side from that point forward. (edits, validation etc.) Once complete, I want jquery to push back via a pagemethod or web service or whatever, the updated EF object so that i can persist it.Reason?I need a highly scalable architecture that handles not storing objects in the session or posting to a database when they haven't been saved to a user. I know I can do this with Silverlight, however given MS's less than convincing comments about Silverlight's future vs HTML 5, I'm strongly leaning towards asp.net or mvc.net if I can come up with a way to use jquery (or even a 3rd party control that does this!) to handle all of the data editing, updating etc. for a master/child display (i.e. Invoice) without the server having to store it and without having to use the viewstate.Ideas?In my mind this would be the holly grail. Render the page, push the data to the controls, have the controls do their thing until save without ever doing server processing, and then on save, push back the object and allow the server to persist it (and probably do server validation before presisting it just in case). By doing this you could make superscalable apps that

Aggregate Object Pass as a hidden value

How to use Html.Hidden for aggregate object?For Example, I have Model1 which aggregates Model2. Model:class Model1{.. public Model2 model2;..} class Model2{ public int id; public int name; .... //there are many fields//  } View:ViewPage is tied with Model1.ViewPage<Model1> I can pass Model2 values by specifiying its fields like<%= Html.HiddenFor(x => x.model2.id) %><%= Html.HiddenFor(x => x.model2.name) %> What I want is to pass Model2 as hidden value without specifying its each field. Any idea how to correct line below<%= Html.HiddenFor(x => x.model2) %>//I'm getting null value for model2 Thanks  

Pass Command to Running Program?


I have a Windows Form app written in C# and I would like a way to close the app from the command line without killing it.

Is there a recommended way to do this gracefully?

Perhaps I can pass a command to the running app to tell it to shutdown?




How to pass SQL server 2005 instance name as a input parameter to restoressp STSADM command


I am facing a problem with restoressp STSADM command. We are using a separate SQL server 2005 instance for our SharePoint PORTAL. For e.g. the instance name is MOSSSQL. I have restored the SSP database from production environment to development environment. But facing the problem when I associate the restored SSP database with new SSP using restoressp STSADM command.

As per Microsoft guideline I have used the restorespp command to attach the database with my new SSP. If I pass the sspdatabaseserver input parameter as “servername\SQL instance name” then its giving me the error message that “required argument are mission – sspdatabase”.

Below is the command

stsadm -o restoressp   
-title “My-SSP"
-url "http://mymoss:11111/"
-ssplogin "username"
-mysiteurl "http://mymoss/mysites/"
-indexserver "MYMOSS"
-indexlocation "e:\logs\"
-sspdatabaseserver "MYMOSS\MOSSSQL "
-sspdatabasename "MySSP1_SSP"
-ssppassword "password"
-searchdatabaseserver "MYMOSS\MOSSSQL"
-searchdatabasename "MySSP1_Search"
-ssl no

Note: I have system admin rights and I am the DB owner



Senthilrajan K

MVC3 + How to pass JSON Object as dictionorary object


In MVC3 Beta version i have action result same like

public ActionResult Save(Dictionary<string, string> dicObject)


I want to pass JSON Object in POST Method from javascript and need to get as dictionoray object


How can i do this? can you write example if possible?


Its urgent, please hep me




Error: Office 2003 SP3 "Command text was not set for the command object"




I have a customer who is using Office 2003 pivot tables against AS2000 cubes. Last week they upgraded to SP3 of Office and now we are getting "Command text was not set for the command object" when trying to refresh / manipulate the pivot tables. Applies to existing pivot tables as well as new ones we create. I found a few references to interesting experiences with SP3, but none that mention this error. We know the cubes are OK because we can use pivot tables against them from another (server) machine that escaped the upgrade. Currently trying to prove or disprove that it was the upgrade specifically that caused the problem.


Has anyone else bumped into something like this? Found a way around it?


Thanks in advance

Pass object to web service


I'd like to pass an object (Digital Persona featureset) to a web service.  Can't seem to find a good way to serialize it.

Any suggestions?


How to pass perameters in exec command when we using XML in stored Procedure?


My SP is:

USE [PrintLableTest]




PROC [dbo].[sp_Insert_Table_PrintLabelTB1XML]

@pData varchar (1000)





DECLARE @CPART nvarchar(50)

DECLARE @ItemNo nvarchar(50)

DECLARE @TPART nvarchar(50)

DECLARE @Code nvarchar(50)

DECLARE @BarCode nvarchar(50)


how to pass a user defined object as an argument to a web server?


I have the following scenario:

1. my web server is in c#, and my web server client is in Java

2. on the java side, I have a user defined object,  (it is implemented as a java bean) and i would like to pass this object, as an argument to one of the web server methods.

3. the problem however is, that on the C# side, i get a compilation error, saying that the type or namespace could not be found.

I read some forum threads saying that it should be serialised, but i have no idea of what to do, to be quite honest. Could someone please help by either explanation or a helpful link with an example?

Many thanks,


Take image or Binary object From SQL and Pass into an XML Document


I have a SQL Table which holds document data in the form of type image (or possibly binary but as far as I can see image is more reliable).

I have a websewrvice which needs to pull the documents from the database, pass the details into an XML file which is retrieved by the application calling the webservice, and then the document files written out at the other end.

My question is what is the best way to go about this?

I believe (but possibly I am wrong) that I need to convert the image data to base64 first.  I know there is the sql command select X from A FOR XML AUTO, BINARY BASE64 which does the conversion but I am not sure how to then write this into an XML document.

Any assistance any one can offer is greatly appreciated as I have not had any experience with working with binary or image, and only very very basic knowledge of XML

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

C# Object Oriented Programming

So far in C# Essentials we have looked at the basics of programming in C# such as variable types and flow control. Although it would be possible to write a functional program using these techniques, there is much more to becoming a proficient C# programmer. C# is, above all, an object oriented programming language and as such any C# programmer will be expected to create object-oriented applications using this language.

Object Oriented Programming

Four core concept of OOP Object Oriented Programming. 1.Inheritance, 2.Polymorphism, 3.Abstraction and 4.Encapsulation
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