DataSource Controls :: Add Parameter To IN Clause In SQL?
Jan 28, 2010
i am developing an application using asp.net and backend server is SQL SERVER 2005.
in my application i have 12 regions. from that 12 regions user will select any of them.
if user select 1,2,3 then i have to pass this string to IN clause
for that i have storedproc like
create procedure sp_updateDistributorContractforAllRegions (
@unitprice float,
@region varchar(50)
)
update employee set UnitPrice=@unitprice where regionid in (@region)
end
GO
here regionid datatype in employee table is INT.
from code behind i am adding the parameter as 1,2,3.when i run the query it gives the error as
Conversion failed when converting the varchar value '1,2,3' to data type int.
View 3 Replies
Similar Messages:
Apr 30, 2010
I have an SqlDataSource query that should use an input parameter for multiple integer values, like:
select * from table1 where TableID IN (1,2,3,4,5)
->
select * from table1 where TableID IN (@IDValues)
How do I do that ? Default parameter settings won't work, returning "invalid integer value" . I suppose that parameter should be passed as some kind of array that SQL recognizes as multiple integer values , but what's the correct way of setting this ?
View 4 Replies
Apr 21, 2010
I am having difficulties using a variable in the "where" clause:
declare @shift_started as datetime
set @shift_started = (SELECT *
FROM OPENQUERY(ADS_RGWP_SERVER, 'SELECT MAX(shift_started) as shift
FROM salestkt AS STK
WHERE NOT EXISTS(SELECT *
FROM SHFTDATE AS SD
WHERE SD.shift_started = STK.shift_started)'))
SELECT *
FROM OPENQUERY(ADS_RGWP_SERVER, ' sum(case when customer_type = ''Inter-Company'' then qty_shipped_today else 0 end) as intercompany_qty,
sum(case when customer_type = ''Charge'' then qty_shipped_today else 0 end) as outside_qty
FROM salestkt
WHERE shift_started ='" & @shift_started & "' ''')
Getting error:
Incorrect syntax near ' & @shift_started & '.
View 9 Replies
Apr 7, 2010
I am trying to do an insert statement to a table from classic ASP.I tried the below:
[Code]....
But, I am getting the error as: Incorrect syntax near the keyword 'where'.How to insert data, using a where clause in the above scenario?
View 5 Replies
Feb 28, 2010
SELECT DISTINCT TblSections.SectionID, TblSections.Description
FROM TblSections INNER JOIN
UMG.Users ON TblSections.SectionID = UMG.Users.SectionID
WHERE (TblSections.Description IS NOT NULL) AND (dbo.Users.LoginName = [@Session(UserName)])
ORDER BY TblSections.Description
I have problem in using Session name in the above BOLD WHERE clause.
View 5 Replies
Feb 28, 2010
I have a GridView that's currently bound to an ObjectDataSource. I would like to see if it's possible to instead bind it to an EntityDataSource. However, I need to be able to apply custom filters to it.
One of the filters corresponds to a bit / boolean property in the database / EntityDataModel. It has 3 possible selections:
[Code]....
[code]....
How can I accomplish the same thing in an eSQL Where clause? There is no COALESCE function, is there an equivalent?
View 1 Replies
Mar 10, 2011
I've already spent hours in searching through the forum to be able to do the following:I have a SQL datasource defined with a checkbox in it. Purpose is to update one column (userid) behind the table for only that row when the checkbox is selected.This is the code I'm currently having:
[Code]....
View 4 Replies
May 25, 2010
I am using Linq to SQL. Tables have timestamp columns and I am using regular Linq methodology in ASP.NET MVC.I do use detached entities and always try to do updates without first querying the database for the original entity. To update an entity I use context.Attach(entity, true) followed by context.SubmitChanges() and all is fine. The sql statement that gets executed looks like:
[Code]...
View 7 Replies
May 25, 2010
Ive created a new LINQ To SQL class and dragged several tables across from my server, in my code I access them like this
[Code]....this is all ok, however, I have several stored procedures that I want to use as well, but when I drag the stored procedures across I get a compilatiopn error
Error 60 'DB_BL.DB_BLDataContext': type used in a using statement must be implicitly convertible to 'System.IDisposable'
how do I use stored procedures from LINQ with a using clause ?
View 7 Replies
May 2, 2010
I'm using asp.net login on a SQL Database.
I have 12 users in my User tabel - one of the user I don't want to have in my select (the user is an admin).
I tried this:
[Code]....
I also tried:
WHERE (dbo.aspnet_Roles.RoleName <> 'Administrators')
Both time it took the user into the table....
If I instead try this
WHERE (dbo.aspnet_Roles.RoleName = 'Administrators')
I get only one row (as expected).
What is wrong with the above sql statement - why can't I get 11 users and not them all (12 users)?
View 3 Replies
May 7, 2010
[Code]....
modifying WHERE Clause and change to RegEx?
View 1 Replies
May 27, 2010
I have some duplication that I need to clean up. I wrote a SQL query that is supposed to return duplicate customers who are located in the same city and zipcode.
I have 2 questions regarding it:
1. Is the query syntax correct to find duplicate records by same city and zipcode, data is being returned but it just returns the same customer a few times?
2. I only need to do the GROUP BY clause for Fullname and City however it gives an error when the other columns are left out. The error is Address, State and Zip not being in the aggregate function or in the group by clause.
Adding all the remaining columns to the GROUP BY clause works.
Query is as below:
[code].....
View 3 Replies
Feb 15, 2010
I know I'm missing something here but I can't figure out what it is. I've got a query joining three tables....accounts, payments, and a table linking the two (there is a M:M relationship).I'm trying to pull a list of all accounts in the account table that have a payment that needs to be resequenced, and also the maximum payment priority if there are any payments that haven't been fully paid. If all payments HAVE been fully paid, I want to return a 0.
It's that last bit of logic that I can't get right. If I include that in the where clause, I get only the accounts that have a payment that hasn't been fully paid. If I take it out, I get all the accounts I get, but I get the highest payment priority whether or not the payment has been fully met.
Here is the query....how do I include the where clause criteria but still include all accounts?
select distinct
bat.acct_id,
isnull(max(isnull(crt.pymt_priority, 0)), 0)[code].....
View 6 Replies
Apr 7, 2010
I'm having trouble writing what should be a simple sub-query using LINQ to Entities. I have two tables: Customers and Orders that have a relation on the CustID field. Not all Customers have a record in the Orders table, while some have mutiple records. In traditional SQL, you could write the query like this: SELECT * FROM Orders where CustID IN (SELECT CustID FROM Customers) I know this could be done as a JOIN in both SQL and L2E, but my actual query is more complex (about 8-9 joins), so I am hoping to find a L2E sub-query equivalent. Something like this:
[Code]....
I know LINQ to Entities does not support the " IN " clause, so I am looking for something that will work in its place.
View 2 Replies
Mar 4, 2010
Here is my LinqDataSource
[Code]....
Here is a button inside a listview that is using the LinqDataSource and also has a pager:
[Code]....
And here is the Code Behind that is triggered by the linkbutton:
[Code]....
It almost works. When i click it it loads and shows the current page of objects that have dates that are higher then todays date. Which is what i want. But as soon as you use the pager to go back or forward it reverts to the default, which is ALL articles, sorted by ID. How can i make the "where" selection stick through the paging?
View 16 Replies
May 20, 2010
I have several web forms which use a GridView linked to a DataSource control which is defined at design time as follows:
<cc1:pgsqldatasource
id="dsStates"
runat="server"
connectionstring="<%$ ConnectionStrings:PgSqlConnection %>"
oldvaluesparameterformatstring="Original_{0}"
providername="<%$ ConnectionStrings:PgSqlConnection.ProviderName %>" >
</cc1:pgsqldatasource>
As you can see, the connectionstring parameter is defined to a specific connection string name and I need to be able to set such a parameter to a different value, for example, to a session variable content.
View 1 Replies
Oct 27, 2010
I am storing a custom "Organisation" object as a session variable. One of the properties of the Organisation object is "OrganisationID" (integer). I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:
[Code]....
However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")? I have tried this, which does not seem to work: <asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />
View 2 Replies
Mar 25, 2010
I need to pass the control parameter to Sql Datasource in code behind,
<asp:ControlParameter ControlID="DDL_RType" Name="rtype" PropertyName="SelectedValue"
View 3 Replies
Aug 3, 2010
What am i missing or doing wrong here, when i debug, im seeing the selected value in the code behind, but when the page loads, it says the following:
Procedure or function 'Onsite_Report_Procedures' expects parameter '@rptNum', which was not supplied.
<asp:SqlDataSource
ID="SQLOnSiteReport"
runat="server"
ConnectionString="<%$ ConnectionStrings:connectn %>"
SelectCommand="Onsite_Report_Procedures"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="@rptNum" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
[Code]....
View 2 Replies
Aug 4, 2010
I have a stored procedure with output parameter. I encapsulate it with Table Adapter and BLL. Call it using ObjectDataSource in conjuction with formview, just like the one in Data Access Tutorial. How do I get the output parameter in event INSERTED of the ObjectDataSource in code behind (VB)?
My stored procedure looks like this:
[Code]....
My BLL code looks like this:
[Code]....
View 2 Replies
Jul 12, 2010
We have a stored procedure which creates and returns as output the next value in line:
[Code]....
Yes, the dullards who created this system not only failed to use an identity for the primary key of this table, they then proceeded to add 1 to a varchar column to create the new value, thus insuring it can never be anything but numeric.
Sigh. I'm told we cannot address that obvious deficiency now, and we have to leave the column as varchar. Double sigh.
If I execute this sproc from SSMS, the hh_num variable is returned as expected:
[Code]....
However, when I run it through the application, the parameter I set up as output does not get its Value attribute changed:
[Code]....
I've verified that the "@hh_num" maintains its direction and name through the ExecuteNonQuery call, but its Value remains an empty string.
View 1 Replies
Jun 5, 2010
I want to use parameter in SQL command, Which the following code is better and why?
string id= getId();
SqlCommand cmd1 = cn1.CreateCommand();
cmd1.CommandText = " INSERT INTO std(idStd) VALUES (idStd=id) ";
cmd1.ExecuteNonQuery();
string idF = getId();
SqlCommand cmd1 = cn1.CreateCommand();
cmd1.CommandText = " INSERT INTO std(idStd) VALUES (idStd=@id) ";
cmd1.Parameters.AddWithValue(@id, idF);
cmd1.ExecuteNonQuery();
View 3 Replies
May 11, 2010
I´m in need to export datagrids to excel. I found a good solution in C#. I´m a newbie at VB.net. I have got it to work but I´m not familar to set the SQL connection and bind data in C#.
I need to declare my query with a calendar parameter but I have no idea how this should be done in this code.
Either, how do I set parameters into the C# code or how can I set a SQLDATASOURCE in the ASPX file and still run all code.
ASPX CODE
[Code]....
And CS
[Code]....
View 3 Replies
Apr 13, 2010
I'm trying to get image from database into picturebox
pictureBox1.Image = Image.FromStream(new MemoryStream((byte[])ds.Tables[0].Rows[i].ItemArray[0]));
But I am getting error:
parameter is not valid
View 1 Replies
Jan 26, 2010
I have the following sub that I need help with an error on. When run error message is saying that the parameter called by the stored proc was not supplied. Am I missing something? I can't seem to find it.....
[Code]....
View 4 Replies