DataSource Controls :: SqlDataSource Variable Number Of Parameters

Mar 7, 2011

I should perform a Query like this Select * from produtcts where model like @MODEL Now if model is selected from combobox, it should be Select * from produtcts where model like '%MODEL1%' while, if selected chooise is null, it should be like each element in my combobox. how should i do this (in SqlDataSource)

View 5 Replies


Similar Messages:

DataSource Controls :: SqlDataSource With A Lot Of Parameters?

Sep 4, 2010

I have asked similiar question before where I have two control on the page header says "username" and "gender". User can select both the control or either one and the page will execute searching based on the criteria supplied. So if username supplied

SELECT * FROM [this_table] WHERE username = @username
and if gender supplied
SELECT * FROM [this_table] WHERE gender = @gender
and if both supplied
SELECT * FROM [this_table] WHERE username = @username AND gender = @gender

I know this sounds not very complicated but in my case, I am having like more than 10 controls up there. It is something likeusername, gender, age, date of brith, title, father name, frst name, last name, blur blur blur and it's a lot then I started to lost. if i were to use if else caluse on code-behind and produce query, it would end up writing a lot of if-else and if i use stored procedure (with if-else) then my stored procedure would contains a lot of if-else statement. I am fairly new to this concept and if I'm on the wrong track, please correct me. Is there any better way to save my hair without actually going through each
if-else statement to build the query ?p.s. I'm using GridView and SqlDataSource command to display the result back on .aspx page.

View 2 Replies

DataSource Controls :: Can Use If Else In Sqldatasource If Else Parameters

Oct 4, 2010

I am trying to check whether a username exists in my database before inserting the new row & display a message to the user if it does.

On my SqlDataSource my InsertCommand looks like this:

InsertCommand="IF NOT EXISTS (SELECT * FROM Users WHERE UserName = @UserName) BEGIN INSERT [Users] ([UserName], [FirstName], [LastName], [City], [State], [Country], [CompanyName], [Active], [PasswordHash]) VALUES (@UserName, @FirstName, @LastName, @City,
@State, @Country, @CompanyName, @Active, @PasswordHash) END"

This works as expected: If the username is unique, the row is created.

If the username already exists, the row is not added.

The problem is, if the row already exists, the insert is rejected but the user is not notified.

So my question is, is there a way I can notify the user?

Maybe something like: InsertCommand = "If Not Exists (select....) Begin Insert...Else Notify User Somehow End This is a basic database, I'm not using the built-in membership provider nor will be.

View 1 Replies

DataSource Controls :: All Parameters Null In Update Of SQLDataSource?

Sep 23, 2010

I have a FormView which is bound to an SQLDataSource. When a user clicks on a save button the form, I need to write any changes made to the FormView back to the table.

I have a Stored Procedure on my MSSQL 2005 database that should be executed when the user clicks on the save button.

It appears the Update is firing, but when I trap the DbCommand object in the SQLDataSource's 'Updating' event, all of the parameters that should be passed to the Stored Procedure are coming through as NULLs. Consequently, the Stored Procedure isn't updating anything.

In the click event of the save button I'm explicitly firing the SQLDataSource's Update method:

[Code]....

The parameters in the SQLDataSource <UpdateParameters></UpdateParameters> section appear to be correct.

Can anyone give me an idea on what to investigate to figure out why it appears the Update is only picking up NULLs?

View 1 Replies

DataSource Controls :: Sqldatasource Insert Parameters Wont Set

Mar 9, 2010

if i do this to set the fetch parameters:

dsList.SelectParameters["client_id"].DefaultValue = Session["client_id"].ToString();

where dsList is my datasource, it works.

but wen i do the samething for the *%^&* insert, it doesnt:

dsList.InsertParameters["client_id"].DefaultValue ="1234";

it keeps saying its null, i dont understand why it woudl be doing this?

View 2 Replies

DataSource Controls :: How To Set Variable In Asp:sqldatasource In Sqlcommand In C#

Jun 28, 2010

i want to ask how to i set variable in asp:sqldatasource in sqlcommand in asp.net c#....
This is my code

asp.net
<dx:ASPxListBox ID="lsAssignToko" runat="server" DataSourceID="SqlDataSource6"
TextField="NAMA" ValueField="ID" AutoPostBack="true"
EnableCallbackMode="True" SelectionMode="CheckColumn"
OnSelectedIndexChanged="lsAssignToko_SelectedIndexChanged">
<Columns>
<dx:ListBoxColumn FieldName="ID"/>
<dx:ListBoxColumn FieldName="NAMA" />
</Columns>
</dx:ASPxListBox>
<asp:SqlDataSource ID="SqlDataSource6" runat="server"
ConnectionString="<%$ ConnectionStrings:Ora2010 %>"
ProviderName="<%$ ConnectionStrings:Ora2010.ProviderName %>"
SelectCommand="SELECT ID, NAMA FROM REF_TOKO WHERE ID IN ( :inTOKO ) ORDER BY NAMA">
<SelectParameters>
<asp:SessionParameter Name="inTOKO" SessionField="inTOKO" Size="200" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
c#
string dummy = "";
string data = "";
string inTK = "";
string inTOKO = "";
//string inTOKO1 = "";
int pot;
for (int i = lsToko.SelectedItems.Count - 1; i >= 0; i--)
{
string tok = lsToko.SelectedItem.Text.ToString();
data = lsToko.SelectedItem.Value.ToString();
dummy = dummy + "" + data + ",";
int index = lsToko.SelectedItem.Index;
lsToko.Items.RemoveAt(index);
}
if (lsToko.SelectedItems.Count <= 1)
{
inTK = dummy.Length.ToString();
pot = int.Parse(dummy.Length.ToString()) - 1;
inTOKO = dummy.Substring(0, pot);
}
Session["inTOKO"] = inTOKO;

the problem is where in my variable inTOKO consist of couple of value...
Example
while variable inTOKO = one value success but while value inTOKO = two value error
inTOKO = 1101111 => success
inTOKO = 1101111,1211321 => not success

View 1 Replies

DataSource Controls :: SQLDataSource Outputting Into A Variable

Jan 17, 2011

It seems really easy to output a sqldatasource into a table but really hard to output a sqldatasource into a variable.

View 2 Replies

DataSource Controls :: Programmatically Adding Parameters To SQLdatasource In Codebehind Using C#

Apr 1, 2011

I have a page called Page2.aspx and it is called by another page called Page1.aspx and Page1.aspx passes two parameters namely: Name and Category to Page2.aspx. Does anyone know why the following code from Page2.aspx is not working and it keeps giving an error message as follows: " You have declare the parameter @Username".

string Cat1;
string Name1;

[Code]....

View 2 Replies

DataSource Controls :: Passing Parameters In Sqldatasource Storeproc, Dropdownlist And Textbox

Jun 8, 2010

I got DDL1: 10 miles

20 miles

TextBox1 : 'AAA20'

Button:

When user selects 10 miles from dropdownlist DDL1 and types AAA20 in textbox1 which is of type text, on button click it has to pull all the columns from database and show results in gridview using sqldatasource store procedure. I'm stuck in server side code..how to pull the data..in store procedure I'm passing two parameters val1 and val2. val1 gets data from DDL1 and val2 gets data when user types in textbox1 and it has to validate the text...see the code below mentioned and tell me how to pass the params and get the data in gridview...

[code]....

View 2 Replies

DataSource Controls :: Mapping SqlDataSource Parameters To Formview With Multiple DataKeys?

Sep 1, 2010

a FormView that is linked to SqlDataSource1a Repeater control (inside the formview) that is linked to SqlDataSource2Thus representing a simple "1 to many" or "parent/child" relationship in the database!qlDataSource1 is simple in that it just retrieves a straight set of records from a table and they are displayed back in the FormView (nothing special happening there).SqlDataSource2 has parameters that filter the contents of the repeater based on the record that is shown in the Formview. This would normally be simple enough to set up by setting the parameter to the formview.selectedvalue property.HOWEVER - THE PROBLEM ARISES...The formview has multiple DataKeyNames because the table that the SqlDataSource1 links to has a compound key. So to filter the Repeater correctlySqlDataSource2 needs to map 3 parameters to 3 data key values in the formview.Any ideas how to do this?I've tried setting the SqlDataSource2 parameters to:

<SelectParameters>
<asp:ControlParameter ControlID="FormView1" Name="Parameter1" PropertyName="DataKey(0)" />
<asp:ControlParameter ControlID="FormView1" Name="Parameter2" PropertyName="DataKey(1)" />

[code]...

View 1 Replies

DataSource Controls :: Retrieve Data From SqlDataSource And Pass To A Variable?

Aug 20, 2010

I have a page in my website where there is very little code-behind. I only have two lines of code in Page_Load() and the rest of the code is declarative ASP.NET code. I have a FormView control which uses a SqlDataSource to get some order information. The SqlDataSource calls a stored procedure called usp_GetOrderDetails, here's the code for the SqlDataSource:

[Code]....

<truncated>

What I want is to grab the screenshotId from the SqlDataSource when the usp_GetOrderDetails stored proc gets called and populate it into a field on the page called screenshotId. I then want to use this screenshotId to get an image from the database based on Id. populating the screenshotId field. How do I do this - do I need to have something like OnDataBound or something like that?

View 4 Replies

DataSource Controls :: Set The Parameter Source Of An SqlDataSource To A Variable From Visual Studio?

May 19, 2010

how can i set the parameter source of an SqlDataSource to a variable from visual studio?

View 2 Replies

Forms Data Controls :: Tie DataSource To SqlDataSource On Aspx Page And Pass Select Parameters?

Nov 10, 2010

[code]....

Is ther a way I can tie DataSource to SqlDataSource on aspx page and pass select parameters?

View 6 Replies

DataSource Controls :: Must Declare The Scalar Variable With Name Parameters?

Mar 1, 2011

I'm getting "Must declare the scalar variable "@ShowTypes"." when I try to run the code below.

[Code]....

View 3 Replies

DataSource Controls :: Objectdatasource With Unpredictable Number Of Input Parameters?

Dec 10, 2010

I'm trying to use an objectdatasource and populate it with a query that has "or" in its where statement. eg: select * from customers where customer_id = "34" or "35" or "36"The problem is... I don't know ahead of time how many of these "or" conditions there will be - the user can choose as many or as few as they want. It seems that if I want to use an objectdatasource tied to a tableadpater I'm forced to know the number of parameters ahead of time so that I can build the objectdatasource's input parameters e.inputparameters.add doesn't work, because the key (in this case "id") is the same for each parameter because the where statment has "or"s....

View 7 Replies

DataSource Controls :: SqlDataSource And Parameters Query / Trying To Accomplish Is Building Dynamic Query

Aug 22, 2010

1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like

SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.

Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).

2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query

(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).

If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.

View 11 Replies

DataSource Controls :: SQLDataSource And Tie A SqlDatasource To A Stored Procedure

May 14, 2010

I am trying to tie a sqlDatasource to a Stored Procedure. The stored procedure looks like...

[Code]........

View 2 Replies

Forms Data Controls :: SqlDataSource Pass Parameters

Mar 15, 2011

I have big filter coming from database by using storedprocedure. This stored procedure contains about 12 parameters. In asp.net page I select these values and after doing that I want to pass these values to SqlDataSourec which is bound to gridview. How can I pass these values to SqlDataSource, manually in codebehind?

View 8 Replies

Forms Data Controls :: How To Add 2 Parameters To One Field Using SqlDataSource

Sep 2, 2010

I am working on a form that I would like to display a dropdownlist or textbox to insert data into the same field.

Currently it is setup where the end user can use one or the other but not both. I am running into a problem getting with the insert parameters for the secondary control. In this case the textbox.

Is it possible to use and Or statment in my Insert Query? I have tried to no avail.

[Code]....

View 3 Replies

Forms Data Controls :: Sqldatasource Using Variable As The Parameter (username)

Jan 19, 2011

I have a Stored Proc which uses a field in the database. that ends up being the user.identity.name. So, when the page loads, it grabs that name and uses it in the stored proc, which I'm which I'm wanting to designate in the sql datasource. But it only gives me choices of querystring, cookie, session, control, etc. My question is how to reference that variable as the parameter in the datasource?

View 3 Replies

C# - Temporary Or Session Variable - Want To Add A Decimal Number To This Variable

Dec 2, 2010

What would be the proper syntax in ASP.NEt 3.5 C# to assign a TextBox value to a temporary or session variable to be manipulated (added, subtracted, multiplied, divided) at different points in the application? I want to add a decimal number to this variable in almost every instance as well.

View 3 Replies

DataSource Controls :: Sqldatasource Insert Method - Copy Data To The Other Datasource By Selecting Checkbox

Feb 25, 2010

i have two sqldatasource controls. one i use to display data in textbox's ,filter'd by a select parameter in page behind code. Once checked, i want to copy this data to the other datasource ,by selecting checkbox.Then display this data in detailsview control.

At present the two datasource controls declared , render data to the page simultaneously during pageload. I want to first check data in textbox's from first source, before second datasource is rendered to screen. note, both are filtered by a page variable. i wish to leave the textbox datasource control in situ, as other controls and code depend on it.The other detailsview datasource is my problem?

View 1 Replies

DataSource Controls :: Number 1 Working As The Same As Number 2?

Apr 22, 2010

any one know why are the following two give me different result? they should both give me no results as the value I give is not available. however, number 1 give me many results, and number 2 works as expected. I'd like the number 1 working as the same as number 2.

1. DECLARE

@SearchMCat nvarchar,
@SearchTitle nvarchar,
@SearchDesc nvarchar
SET @SearchMCat = 'fjiewo;jafoia'
SET @SearchTitle = 'fryere'
SET @SearchDesc = 'fdsfdsafae33'
SELECT ArticleCategory.CategoryDisplayName, Article.AudioPlaybackTargetTabID, Article.VideoPlaybackTargetTabID, Article.StartTime, Article.DateAdded, Article.Body, Article.Synopsis, Article.Title, Article.ArticleHasAudio, Article.ArticleHasVideo, Article.createdBy,
Article.RatingTotal, Article.RatingCount, Article.ArticleID, ArticleCategory.CategoryName
FROM ArticleCategory RIGHT OUTER JOIN Article ON ArticleCategory.ArticleCategoryID = Article.MasterCategory
WHERE (ArticleCategory.CategoryName LIKE '%' + @SearchMCat + '%') or (Article.Title LIKE '%' + @SearchTitle + '%') or (Article.Body LIKE '%' + @SearchDesc + '%')

2.

SELECT ArticleCategory.CategoryDisplayName, Article.AudioPlaybackTargetTabID, Article.VideoPlaybackTargetTabID, Article.StartTime, Article.DateAdded, Article.Body, Article.Synopsis, Article.Title, Article.ArticleHasAudio, Article.ArticleHasVideo, Article.createdBy, Article.RatingTotal, Article.RatingCount, Article.ArticleID, ArticleCategory.CategoryName
FROM ArticleCategory RIGHT OUTER JOIN Article ON ArticleCategory.ArticleCategoryID = Article.MasterCategory
WHERE (ArticleCategory.CategoryName LIKE '%' + 'fdsafdsafdsa' + '%') or (Article.Title LIKE '%' + 'fffaery' + '%') or (Article.Body LIKE '%' + 'fdas3r43ffdsa' + '%')

View 4 Replies

C# - Set Sql Parameters For An SqlDatasource In The Code Behind

Feb 9, 2011

How can i set sql parameters for an sqlDatasource in the code behind?

I am trying like this:

[code]....

View 2 Replies

Forms Data Controls :: Embeb A Variable Number Of Videos?

Aug 21, 2010

I need to provide some alternate content for my non-Flash users. I have a directory of video files that is scanned using the DirectoryInfo() function, and I want to use the results to embed all files ending in ".mov" in QuickTime players on a web form. How would you approach this? Right now I am using the count on the array of videos to determine how many times to repeat the embed code. But this seems inelegant.

Is there a way to have a single QuickTime player.ascx control that gets duplicated according to the number of videos available for display?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved