Passing a value at a sproc that populates dataset


I select an item  from a list box in order that  it's value will be added as a parameter to a sproc

this is the code;

command.Parameters.Add("@DepNum",SqlDbType.NChar).Value = Lbdepartment.SelectedValue

my sproc is a select sproc and it sepose to retrive the rows to the dataset according to the selected value.

this is the sproc:

ALTER PROCEDURE [dbo].[ShowBooks]

@DepNum nchar(10)


SELECT * from BookTable

where dep_id=@DepNum   // dep_id is a column in the table


From some reason, while the connection is o.k the syntax is o.k and the procedure is being recignized but is doesn't retrive the rows to the dataset

what can be wrong(as I said the other parts of syntax are o.k)??


click! click!
5/3/2009 6:27:28 PM 29906 articles. 0 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 56

 Are you sure you want to compare the dep_id column with the @DepNum?  Maybe there is another column in the table you should be comparing it to?

5/3/2009 6:36:22 PM

yes it is correct although it seems it isn't.

click! click!
5/3/2009 8:41:35 PM

Hi, can you pls show your entire code?

Hope This One Can Help.

To Be Happy Is To Be YourSelf

Please remember to mark my reply as answers if it's the answer to your question.
5/4/2009 12:56:20 AM

have you ever tried to debug and get the value from the dropdownlist and directly run the SQL? does it really returns a value? are you sure the selected value exist in the database?

5/4/2009 4:58:40 AM

the entire code:


protected void Button1_Click(object sender, EventArgs e)
        SqlConnection contact = new SqlConnection(ConnectingPpl.StartConnection());
        SqlDataAdapter da = new SqlDataAdapter();
        SqlCommand command = new SqlCommand("ShowBooks" , contact);

        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@DepNum",SqlDbType.NChar).Value = Lbdepartment.SelectedValue;
        da.SelectCommand = command;
        DataSet ds = new DataSet();
        da.Fill(ds, "BookTable");




            Label7.Text = "Create new user FAILED!";



            if (contact.State == ConnectionState.Open)




 and yes i have used debugging and ran the query directly and it worked, the thing is i need to use sproc because i want the query to be based on a variable that stores the dep_id which is depended on the user's selection.
click! click!
5/5/2009 1:11:08 AM

put the after the SQLCommand command = new SqlCommand("ShowBooks", contact);


5/5/2009 1:58:12 AM

Similar Artilces:

Passing values to sql datasource
HiI am trying to pass the membership username to the sqldatasource of a gridview as below; <asp:SqlDataSource ID="EventsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnStr %>" SelectCommand="SELECT * FROM [MyTable] WHERE [Username] = '<%Me.User.Identity.Name%>'"></asp:SqlDataSource> It is not working. How can I do it correctly?ThanksRegards Hi There, You can add SQLParameter and set the parameter in code behind: ASPX:  <asp:SqlDataSource ID="EventsSql...

Ajax Cascading Drop Down pass value to SQL datasource
I am trying to pass the "text" value of a Ajax Cascading Drop Down box to a SQL Datasource.  When I bind the dropdown to the appropriate field and insert the record, the "ID" field is populated instead of the "text".  Example Car Name is BMW / Record ID is 1 Car Name is Ford / Record ID is 2 The 1 or 2 will pass to the database but not the BMW or Ford. Is there anyway to do this?  The dropdown lives in a gridview. Code is:<asp:DropDownList ID="ddlCategorys" runat="server" DataSourceID="ods_Categorys" DataT...

How to pass parameter value from one sql datasource to another?
Hi everybody, Here is the problem, how to pass the values from one datasource to another one on the same aspx page, without coding?  I have a page with FormView control to present data for one selected record from a search page, with edit item and insert item templates created. The main sql datasource keeps control on everything with select, update, delete and insert methods. For insert I am using existing stored procedure, for which the wizard generated all the required parameters. In Command and Parameter Editor I can see them, and I need to define all of th...

Strongly Typed Dataset. is there a way to pass in a null value to a bit in SQL Server
i have a strongly typed dataset created using a SQL2003 spone of the insert parameters is of datatype bit. The ABContact field can be null so i need a way of passing in NULL value to the stored procedure. but i dont seem to be able to do this for type bit. the web service code for calling the stored procedure will only ever accept either TRUE or FALSE and not DBNULL.Value is it possible to somehow pass a NULL value into the Insert command. only thing i could think of changing the sp so that the input parameter was an integer value then, for example, if the integer value was 0(False), 1(Tr...

How to pass a value for QueryStringParameter from GridView on one page to SQL datasource on another page
Hi,I am trying to pass a value for the QueryStringParameter EmployeeID from a GridView on one page to a SQL datasource on another. I have set up the GridView's hyperlink field as follows:<asp:HyperLinkFieldText="Contact me"DataTextFormatString="{0}"DataNavigateUrlFields="EmployeeID"DataNavigateUrlFormatString="~/people/contactme.aspx?EmployeeID={0}"Target="_blank"/>and when I run the page and click the hyperlink, it takes me to the correct URL (e.g. when the EmployeeID is 106, http://myserver/mysite/people/contactme.aspx...

Extract values from SQL Results and Pass value to variable
What is the syntax to get the value from a sql command and pass it to a variable? This is what I have...VB.NET This stored procedure returns a number.... cmdSelectEmp = New SQLCommand ("NIO_Get_EMP_ID",Conn) cmdSelectEmp.Commandtype = CommandType.StoredProcedure cmdSelectemp.Parameters.Add("@User",cUser) How can I pass that number to my variable? myVar=We must become the change that we want to see! Add a parameter with .Direction = to ParameterDirection.ReturnValue and check that value: cmdSelectemp.Parameters.Add("returnValue").Di...

How do I check to see if a value returned from a sql datasource equals a listitem value
I'm trying to see if this listitem equals a value returned in my sql data source, but I get keep getting a error saying  'Item' is not a member of 'System.Web.UI.WebControls.SqlDataSource'.    How do I check if the employeeID returned is equal to the li.value? For Each li As ListItem In BillingEmployeeID.Items If li.Value = getEmployeewithMostOpenClient.Item("employeeID") ThenxxxxxxxEnd If NextNever make important decisions on a Monday! Try Items.FindByValue() or Items.FindByText() method. Something like this... string szValueFromDataso...

Passing boolean values to oracle function / procedure from C#.Net
Hi,  I dont know how to pass boolean values to oracle function / procedure arguments, could you please help me to know ?  Thank you, Sreedhar After spending lot of time on google, I understand C#.Net doest support PL/SQL boolean values. Thanks Sreedhar...

Pass Dataset value
Hi there,Is there any better way to pass a dataset within application instead of using Session? So, if I get my dataset from data access layer, then I wanna using that dataset in OnPageIndexChanged method, how I can pass those data?Any suggestion.Thanks,Ron.Best regards,Ron....

gridview populated from datasource but want to add template column with different values from another datasource
 hi i have a gridview populated from datasource but want to add template column the is databound to a different datasource bringing different values and adding them to the same row but on new columns.. i have it bringing in the data but my problem is that it is not matching the daa to the correct primary key "ipc" its just outputting the list one after another.. my code is Dim col As System.Data.DataView col = AccessDataSource10.Select(New DataSourceSelectArguments()) For Each row As GridViewRow In GridView1.Rows Dim ipc As String = GridView1...

How do i pass an ID value from one datasource to another datasource located inside a repeater control?
Hello,  I am trying to develop a page that allows me to update stages for each item that does not have a status of complete.  I am going to break out what i am trying to do in 4 sections (hopefully to explain this as best as i can), why, what, goal, and problem. Why am i trying to do this? Every day we recieve media in the mail, and we have to put it online.  There are 5 stages we must pass to get this media online, Received, Importing, Compressing, Uploading, and Complete.  I am trying to create a page that will help our media loaders easily keep track of th...

passed value populates from previous page. Populates textbox & cues datagrid (without clicking button on target page)
This is a hodgepodge of our work that I'm testing to later integrate into the full project.  So here goes, I have two pages Page1.aspx & Page2.aspx Page1 has a simple form w/ a textbox & button to query my db.  I grab & forward this value to Page2 where it lands in a textbox named TextB_100 at Page Load.   Page 2:  The value passed to TextB_100 becomes the input box for a new query to populate a datagrid.  Again when Page2 loads the value is there waiting.  To execute the grid there is a button called But...

Pass value from Flash to .NET?
Hi! I wonder if someone can help me with sending a value wich comes from an "input_text" in flash to be handled in my aspx page in codebehind? I'm using VB and flash CS3   create a .net page that will handle querystring values that you then do some additional codebehind functions on.  in flash, just pass the parameter in the getURL() method.  so something like getURL("mypage.aspx?id=" + input_textvarname,etc,etc)- Always learning something new in .Net Thanks alot! It works fine! This might be a stupid question but how can I send Multiple ...

pass string values to a dataset
I have a string variable str and that string variable has values seperated by a colon (,) str = Alaska, Arizona, california etc... How can i pass these  values in a string to  a dataset?   Do you intend to bind these values to your dataset and display them?  I'm not exactly sure what you mean by pass them to the dataset. Do you want to store the values in a table column. If I am right.. you need to split the string in array and then convert that array into parameter collection and it should workThere is a problem because somewhere there is a solution of t...

Web resources about - Passing a value at a sproc that populates dataset -

Facebook Fans Populate National Car Rental Playlist
... its Facebook fans are listening to, so the company teamed up with music-streaming service Songza to allow users who like its page to help populate ...

Facebook Launches Integrations With Spotify, Netflix and More to Populate the Ticker with Playable Content ...
A wide variety of media partners and news publishers have partnered with Facebook to allow uses to publish content to the site that can be immediately ...

Perish the populate thought
Population size and growth, resources and climate change are obviously linked.

Islamic State militants raping thousands of women to populate caliphate, Iraqi official claims
ISLAMIC State fighters are reportedly raping thousands of women in Iraq and Syria to mass-produce spawn who&#8217;ll follow in their footsteps. ...

Researchers craft bot to populate Wikipedia with gene data
In order to help make Wikipedia a better source of information for biologists …

Are Chuck Schumer and Steve Israel Working To Populate Congress In The Image Of Scoop Jackson?
History lesson: In 1972 and again in 1976, the Beltway's conservative Democratic Establishment had found its man. The preferred candidate of ...

Extreme Shrimps Could Possibly be Sent to Populate Europa, NASA Reports
Rimicaris hybisae live on the edges of hydrothermal vents 7,500 feet underwater whose temperatures reach 750 degrees Fahrenheit.

Glowing robotic tentacles populate this Petting Zoo
(Credit: Minimaforms) If you swing by the Petting Zoo in Orleans, France, don't expect to see goats. The robotic "pets" that reside there hang ... - Millionaires populate U.S. Senate - Jun. 13, 2003
The U.S. Senate showed once more why it's sometimes called the millionaires' club.

Pokémon 2DS bundles soon to populate Australian store shelves
Australian gamers who have yet to pick up Pokémon X and Pokémon Y will be able to purchase one of two new Nintendo 2DS system bundles on June ...

Resources last updated: 12/28/2015 8:15:15 PM