TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Naresh Seth
NA
84
1.8k
How to pass parameter to only one 'SELECT' ?
Jul 6 2018 2:11 PM
There is a stored proc as below with two selects. And i have to pass only one parameter (i.e Name ) to one SELECT through SQLQuery. How could i achieve that?
Stored procedure :
"USE [CustomerDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetCustomers] @Name nvarchar(max), @ZipCode int
AS
SELECT [Id], [Name],[ZipCode] FROM [dbo].[Customers] WHERE [Name] LIKE (@Name);
SELECT [Id], [Name],[ZipCode] FROM [dbo].[Customers] WHERE [ZipCode] = @ZipCode;
GO"
public List
GetCustomersByName(string name, int zipcode)
{
List
ilst = new List
();
using (CustomerContext cx = new CustomerContext())
{
var result = cx.Database.SqlQuery
("GetCustomers. @Name", new SqlParameter("@Name", name));
foreach (Customer c in result)
{
Customer cust = new Customer();
cust.Name = c.Name;
cust.Zipcode = c.Zipcode;
ilst.Add(cust);
Console.WriteLine(cust.Name, cust.Zipcode);
}
}
return ilst;
}
Please assist.
Reply
Answers (
11
)
string replacement is any better way?
Integrate Angular 6 with MVC Project