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


Similar Messages:

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 :: 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

Forms Data Controls :: Pass Multiple Parameters In A HyperLinkField Field?

Aug 15, 2010

I am creating a grid with a code behind and in the hyper link column I would like to pass some parameters before passing users to a new page. If I just use one parameter, the CustomerID in the dataNavigateUrlFields and dataTextField then the

linkField.DataNavigateUrlFormatString = @"/details.aspx?Customerid={0}";

statment works fine.

Now my requirement is to pass multiple parameters and when I tried the following it gave a

'A field or property with the name 'System.String[]' was not found on the selected data source.'

Here is the code snippet:

HyperLinkField linkField = new HyperLinkField();
string[] dataNavigateUrlFields = { "CustomerID", "CompanyName", "FirstName" };
linkField.DataNavigateUrlFields = dataNavigateUrlFields;
string[] dataTextField = { "CustomerID", "CompanyName", "FirstName" };
linkField.DataTextField = dataTextField.ToString();
linkField.DataTextField = "CustomerID";
linkField.HeaderText = "Customer ID";
linkField.DataNavigateUrlFormatString = @"/details.aspx?Customerid={0}&CompanyName={1}&FirstName={2}";

Does some one know how pass the multiple parameters via the hyperlinkfield in C#?

View 3 Replies

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 :: 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

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 :: Use Is Null In Query Without Using Parameters For It Or Should Use Parameters For This Field Where Value Is NULL

Jan 21, 2010

here is my code for selectiong some records from db table

string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc";
SqlCommand com = new SqlCommand(strSql, con);
com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];

here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this

View 8 Replies

Web Forms :: Passing Parameters In Dropdownlist And Sqldatasource

Jun 3, 2010

I am trying to pass the parameters dynamically thru Sqldatasource and get the results in grid view. Based on the dropdown list selection it has to show the results in grid view. When I hard code its giving correct results but when passing thru parameters i'm unable to get the results in grid view.

Output shud be something like this:

Select the value: 123

124

125.

Lets say user selects '123', the query it runs in sqldatasource is Select col1,col2,col3 from table1 where col1 LIKE '123%'

results will be 12301,12302,12303 with other columns in grid view.

[code]....

View 6 Replies

VS 2008 Submitting Data Field In Different Format Using SQLDataSource

Mar 2, 2010

On my web pages I display the data as mm/dd/yyyy and that is how the user will enter the dates as well. But when I pass the textbox control that has the date in it as a parameter to the SQLDataSource control, I need it to be sent in the YYYY-MM-DD format for the AS400. Is there a way it can be changed in between?

View 7 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

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

Using Parameters To Configure The Table Name In An SqlDataSource SelectCommand?

Dec 15, 2010

I have an ASP.NET 3.5 web form with a DropDownList bound to a table of company names in a database. I also have a data bound GridView which I would like to update with data from the database depending on the company name selected in the DropDownList, so that the SelectCommand for the GridView's SqlDataSource is:

SELECT Registration, Telephone, Profile FROM {CompanyName}_VehicleData

Where {CompanyName} is whatever is selected in the DropDownList. I've used the Command and Parameter Editor to create a ControlParameter pointing to the SelectedValue of the DropDownList, but I don't know how to write the SelectCommand query to concatenate the parameter to '_VehicleData'.

View 1 Replies

VS 2008 - Error With Adding Parameters To SQLDatasource Control

Aug 19, 2011

I use the sqldatasource control a lot with stored procedures. But this time I'm using some code I found online where I am defining the new sqldatasource in the code and using it. You can see this below. I am getting a NullReferenceException on the first SelectParameters line and not sure why. Do I need to add the parameters different?

Code:
Dim SqlDataSource As New System.Web.UI.WebControls.SqlDataSource()
SqlDataSource.ConnectionString = ConnectionString
SqlDataSource.SelectCommand = "MySprocName"
SqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
SqlDataSource.SelectParameters("Distance").DefaultValue = 25
SqlDataSource.SelectParameters("ZipCode").DefaultValue = "31410"
Dim arg As New DataSourceSelectArguments()
Dim dv As System.Data.DataView = DirectCast(SqlDataSource.[Select](arg), System.Data.DataView)

View 2 Replies

AJAX :: SQLDataSource With Parameters Doesn't Work Inside A ModalPopup?

Jun 8, 2010

although I've searched already, but here is the thing:I have a ModalPopup wich have a Textbox, a Button and a GridView inside. The Gridview is binded to a SQLDatasource object, and the Select query is something like "SELECT field_1, field_2, field_3, field_4 FROM Table_Name WHERE field_1 LIKE '%@Parameter_2%'".This ModalPopup is used (or gonna be used) to search for a field, so the parameters received by the Query is the text inside the Textbox, I've linked thid inside the SQLDataSource Wizard.The problem is that everything works perfectly fine... inside the panel WITHOUT the ModalPopup Extender, but whe I add the Extender the filter function doesn't work.Here is my code:

[Code]....

Notes: I have a ScriptManager inside the MasterPage, so I don't have to insert one in every page. Also I've tested the code in a new page (the one I use for testing), and it works fine, it filters and everything, the problem is when I add a ModalPopup to the panel.

View 3 Replies

Forms Data Controls :: How To Display A Checked Checkbox When Field Value=1 And Unchecked When Field Value=0

Apr 22, 2010

I am using a GridView Control to display multiple fileds with 0's and 1's.

I am using template fields where CheckBoxes are used.

Where exactly and how do I apply the Logic to get a checked CheckBox when field Value=1 and unchecked CheckBox when field Value=2 .Also some times to be able to write a YES where fieldValue=1 or NO where filedValue=0

Do I apply this logic using asp or C#? How?

View 2 Replies

Forms Data Controls :: Disable/Invisible Field In Gridview Based On Another Field?

Jul 9, 2010

I have 2 fields in my gridview one called ScriptType the other BagNo, when a user click the edit button, I would like the BagNo filed to be disabled if the ScriptType field is = "TTA" and enabled otherwise. How can I do this?..something along these lines see below..I am using VB..

[code]...

View 14 Replies

Forms Data Controls :: A Required Input Field DropDownList If Old Records Have Null In This Field?

Apr 1, 2011

I have a DetailsView on the page and I have made one of the fields a TemplateField. In the EditItemTemplate and InsertItemTemplate I have a DropdownList that is databound to a table in my Sql Server database. I wanted to add an initial value to the DropdownList
namely "- select -" .

I set the AppendDataBoundItems property to true and added the initial value as a ListItem.Markup of the DropdownList

<asp:DropDownList ID="DropDownList_HP" runat="server"

AppendDataBoundItems="True" DataSourceID="SqlDataSource_HP" [code]...

This works fine for new input. The problem is however that the database already has records that were entered through a Windows Application and many of these records has a null value in this field and exceptions are thrown when I tried to open these records
and the system tried to set the SelectedValue of the DropdownList.After some more searching I found this help

http://msdn.microsoft.com/en-us/library/ms366709.aspx

So I changed the ListItem in the DropDownList markup to the following:

<asp:DropDownList ID="DropDownList_RefHospDV4" runat="server"

AppendDataBoundItems="True" DataSourceID="SqlDataSource_RefHosp" [code]...

This now solved the problem of opening a record where the value is null in the database, BUT now the RequiredFieldValidator is not validating anymore to make sure that a databound item is selected for this field and not the initial value "- select -". So basically now it is not checking anymore to see if valid input has been entered for the DropDownList and it accepts "- select -" thus it acts as if the field is not a required field anymore.

In short what is required is that I want to make sure that the user enters a valid selection in the DropDownList, but it must also cater for old records that do not have this field entered yet so that those old records can be opened in the DetailsView .Opening Old records (with null in that field):When these old records are opened in the DetailsView the DropDownlist should show "- select -" when the value in the database is null.

Saving records (old or new records):When saving the record in Insert mode or Update mode the RequiredFieldValidator should show that a valid input is not selected if the DropDownList is still on "- select -".

View 1 Replies

Forms Data Controls :: How To Use A Field Value In Another Field In Gridview

Dec 19, 2010

I have a grid view, and I add new column as a hyper link field, I want the navigationURL for this field to be Pageexample.aspx?ID=other field value like this

[code]...

is that possible ?

View 2 Replies

Bind A Text Box To A Field Selected By SQLDataSource (VB.NET)

Feb 8, 2011

I'm looking for the easiest way to bind data from a SqlDataSource to textboxes dropped in Visual Studio 2008.

For example, I have 4 textboxes currently that have Address, City, State, Zip. I also have a SqlDataSource on the page fetching the ID of the record and selecting those 4 fields based on ID.

How am I able to quickly bind each box to those particular fields selected? I would think this would be really straight forward - but seems it's not. Seems like the answer is funneled towards having to create a GridView or some type of control.

View 1 Replies







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