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


Similar Messages:

DataSource Controls :: Null Option In Qurery Parameters / Using Query With DropDownList And Textbox Controls?

Dec 18, 2010

I have SqlDataSource with a few parameters (code below). If I understand this code correctly if parameter is NULL I should receive all items from the query. It works fine with query editor. But when I try to use this query on my page - with DropDownList and Textbox controls as source of parameters - it doesn't work. I suspect that main reason of problem is value which these controls pass to the query. Instead of NULL this is an empty string. Is it possible to pass NULL value from DropDownList or TextBox to
the SqlDataSource?

[Code]....
[Code]....

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

Web Forms :: Why Are These Parameters Null

Feb 6, 2010

I get an exception when deleting a row that says "Value cannot be null. Parameter Name: Original_ProductName" When I check the locals window the value is null. The ProductID has a value, but all of the other fields that are prefaced with the "original_" are null. I don't see what the issue is. I checked the bll and the gridview itself and they seem to have the necessary things. I didn't post all of the gridview and objectdatasource for brevity.

the exception listed the Original_ProductName in caps. In the code it is listed as "original_productName". This seems to be done consistently throughout so I don't think it is a capitalization issue.

[Code]....

[Code]....

View 2 Replies

MVC :: In Second (and Third) Cases I Receive To It Null For Both Parameters?

Jul 5, 2010

I use T4MVC v.2.6.15 I have following problem with registering routes:My problem route is following:

[Code]....

when I use first scenario (with plain mvc rules) my controller

[Code]....

receives empty line and 1 as a parameters. But in second (and third) cases I receive to it null for both parameters.What do I do incorrectly?

View 3 Replies

Stored Procedure Parameters - Sometimes NULL?

Jan 19, 2011

i have a stored procedure to update a table. not all fields are required and some can be blank.for example, title is not required, but when it's blank i get an error

Dim ptitle As New SqlParameter("@title", SqlDbType.NVarChar, 20)
ptitle.Value = objFormat.CheckSQL(title)
myCommand.Parameters.Add(ptitle)
ex {"Procedure or Function 'sp_UpdateUser' expects parameter '@title', which was not supplied."} System.Exception


how can i fix it so that it allows for nulls if the data field is blank?

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

MVC :: Custom Route Returns 404 When All Optional Parameters Are Null?

Feb 19, 2010

I get a 404 error when I navigate to the following URL using the route below:

http://localhost:53999/properties/

However, all the following are correctly routed to the List action in my controller:

http://localhost:53999/properties/usa/new-york/manhattan/12

http://localhost:53999/properties/usa/new-york/manhattan

http://localhost:53999/properties/usa/new-york

http://localhost:53999/properties/usa [Code]....

In PropertiesController.cs: [Code]....

It looks like it should just go to the default controller/action,

View 5 Replies

State Management :: Session Parameters Are Null In An IFrame

Jan 30, 2011

I have a "one page application" (ASP.NET 3.5, VS 2008, IE7) that uses Default.aspx as it's page, and holds an iFrame within "floating panel" (asp:Panel with extenders).

As the desired behavior is to allow users to reopen the application by refreshing the page,

I added this to the Default.aspx.cs:
protected override void OnPreInit(EventArgs e)
{
if (!IsCallback && !IsPostBack)
{
Session.RemoveAll();
GeoApplication.DAL pDAL = new GeoApplication.DAL();
Session["DALinstance"] = pDAL;
}
}

However, when the iFrame page lifecycle starts, the Session["DALinstance"] parameter is null. I've tried to put some additional parameters and those were null as well.

View 5 Replies

MVC :: HttpPost And Arrays - Products Parameters Came With Null And Zero Value In Post ?

Jan 7, 2011

I am only start learning MVC 2.I have class

[Code].... I wrote HttpPost in controller

[Code]....

my page has next code:

[Code]....

Why InvoiceFinalViewModel view, List<Product> products parameters came with null and zero value in post ?

How correct bind arrays in MVC ?

View 12 Replies

EntityDataSource Null Update Parameters Not Getting Marked Modified

Feb 24, 2011

I am using an EntityDataSource with a FormView on VB.NET application. The FormView contains an AjaxControlToolKit TabContains with multiple tabs. Due to the fact that each tab is a naming container, Bind doesn't work properly for updating values (as discovered from reading other posts on stackoverflow). I instead have to declare UpdateParameters on my EntityDataSource. Example markup is as follows:

<asp:FormView ID="fv" runat="server" DataSourceID="eds" DataKeyNames="ID">
<EditItemTemplate>
<asp:TabContainer ID="tc" runat="server">
<asp:TabPanel ID="tp" runat="server" HeaderText="Tab 1">

[Code]....

This works great, until a customer is edited and their name is set to nothing (assuming in this case, a null name is allowed). The Name UpdateParameter is set to Null but the ObjectStateEntry is not set to modified for Null properties, even if previously the Entity had a value specified. As long as the name is changed to something other than Null, everything is updated correctly.

I found a workaround by putting the following code in the Updating event of the EntityDataSource.

Dim ose As ObjectStateEntry = context.ObjectStateManager.GetObjectStateEntry(action)
For Each p As Parameter In eds.UpdateParameters
ose.SetModifiedProperty(p.Name)
Next

This makes sure that each property in the UpdateParameters has its state set to modified. It works, but it seems like a hack and I can see it causing problems down the road. Is there anything else I could do?

View 1 Replies

DataSource Controls :: Combobox And Query Parameters With IN?

May 19, 2010

with query parameters in ASP.NET. For example, if I have query:

[Code]....

for parameter @id I intend to use combobox. Everything is just fine with this example, problem begins when I try to use IN clause.What I need is query like this:

[Code]....

[Code]....

View 2 Replies

DataSource Controls :: Sql Query - Get Minimum Price When Pass Parameters - Code Is Duplicating Value

Feb 1, 2010

here is my query which is not working properly. I have 5 fields in my table Company, Reseller, Item, Code, Price. How can i get minimum Price when i pass parameters for Code is dublication value

Company Reseller Item Code Price
A A-1 I1 C1 20
B A-21 I2 C2 13
C A-B I1 C1 19

select Company,Reseller,Item,Code,Min(Price) from Table1 where code='C1' order by Code HOW CAN I GET THIS BELOW TYPE OF RESULT

Company Reseller Item Code Price
A A-1 I1 C1 20
C A-B I1 C1 19

View 17 Replies

DataSource Controls :: TableAdapter Null In A Query Parameter

Jan 6, 2010

I am creating a TableAdapter using corresponding wizard, with a GetDataByID() query. The select statement is like this:select * from books where ID = ?Thus books are filtered by ID. But in case a null is passed as a parameter, I want to select all records rather than none. Could you please tell me how I can do it?

View 4 Replies

DataSource Controls :: Insert DBNull Value Into Varchar 1 Null Field

Aug 12, 2010

My database includes a table with sever filds which are defined as (varchar(1),null), I tried using DBNull.Value, null, ' ' but cannot get a null inserted in that field of the database,

[Code]....

View 4 Replies

DataSource Controls :: Passing Null Value To A Decimal Datatupe Field?

Jun 16, 2010

I have req where i have to pass null value,if value coming from db is null.Problem here is the field datatype is 'Decimal' so all the time even though value is null ,its passing as zero.How can I pass a null value to decimal field in C#.

FieldValue = (reader["Field"] ==
DBNull.Value) ?
Convert.ToDecimal(null) :
Convert.ToDecimal(reader["field"]);

What I want is ,Field value will get null value assigned not zero.

View 4 Replies

SQL Server :: Handling NULL...Field Not Updating When NULL?

Nov 6, 2010

i am using the following in a stored procedure.

[code]....

[Code]....Handling NULL...Field not updating when NULL?

View 3 Replies

ADO.NET :: Parameters And Null Values / Showing In Database (Empty Like "Space") In Text Fields

Sep 27, 2010

I was develop an application (ASP.Net) Using (VS.Net C# 2010 & SQL Server 2008)

And I was applying (3-tyer Basics) and I'm not using wizard forever in my application.

The problem is :

When I try to passing the parameters to database, some fields I don't type it But it's show in database (Empty like "Space") in text fields and (01-01-1900) in date fields

Although it's must be (Null) .

How I can pass parameters with Null Values for the fields that's not typed?

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 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 :: Displaying A Null Or Empty Cell For A Null Datetime Database Value In Gridview?

Dec 6, 2010

I have setup my business object to have a create_date and edit_date members both datetime datatypes. My company want to display the create_date and edit_date fields in a gridview for each transaction. The problem i have is that after insterting a record it will have a valid create_date but no edit_date and when displayed in the gridview it defaults to datetime.minvalue (My default). How on earth do i show an empty field in my gridview for a null datetime field in the database?

I am using similar architecture to the Imar Spaanjaars example of a tiered solution. With a few small tweeks it has worked well for me for ages. I am passing a List<Database> to my object datasource which connects to my gridview.

View 3 Replies

Forms Data Controls :: How To Add Optional Parameters In Query String

Jan 30, 2010

I have a data grid with a lot of information on it - to easily filter the data, I would like to be able to pass parameters to it. My problem is that I do not want the parameters to be required. So if I just put 1 or 2 of them in the query string, I would like for it to return all of the data related to those two parameters.I am using a data grid & stored procedures:My Stored Procedure looks like this:

[Code]...

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

SQL Server :: What If Multiple Output Parameters And Input Parameters And Also Want A Select Table

Feb 16, 2011

[Code]....

When I want to get the output values its okay but I also want returning a table as a result data.But Datareader has no rows.is it possible if I want a returning query result and multiple output values togather ?I wrote a test above.I can get output values as sqlparameters. But Datareader attached to a Gridview is empty.can you detect whats wrong here and it doesnt return a query result.So stored procedure is not standart or ı am doing something wrong.this doesnt raise any exception.but not returning any data.

[code]....

View 8 Replies

How To Define A Route That Have 2 Optional Parameters In The Middle Of The URL The Start An End Parameters Are Digits

Jun 7, 2010

I want to define a route that have 2 optional parameters in the middle of the URL the start an end parameters are digits

[Code].....

View 1 Replies







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