I am using EF6 and I need to execute stored procedure. It takes two parameters: mIIN varchar(12), which is input string mXMLOutput varchar(max), which is the result of execution It works fine when I call it from Management Studio. However, when I use the following code: which results in the error Procedure or function ‘GetInfo’ expects parameter ‘@mIIN’, which was
Tag: c#
EF – AND NOT EXISTS (SELECT 1 …) with Entity Framework
I am trying to run this query using Entity Framework in my ASP.NET MVC project but I am not succeeding. Could anyone help me do this using LINQ? TABLES: Answer The direct equivalent LINQ construct of SQL NOT EXISTS (…) is !Any(…). So translates to
C# sql create one connection and open and close for each query
I recently inherited a C# Web app that creates a new connection for every query like so: I understand that this is typically the best way to do it, but is it acceptable or “best practice” to have the constructor create the connection object, and then have each method/Query open and then close that connection like so: I prefer the
Using SqlQuery<Dictionary> in Entity Framework 6
I’m trying to execute a SQL query in EF 6. The select query returns two string columns, e.g. select ‘a’, ‘b’, and can have any number of rows. I’d like to map the result to a dictionary, but I can’t …
Can’t retrieve data from SqlDataReader in C#
I need to insert values into several tables first I have to retrieve university id from table college and then insert faculty name into table faculty and get generated by SQL Server ID. After all of this I have to insert both ids into an other table. Problem is that I have to close readers and after I do it
Replace [ ] bracket in a string
I have a string that includes brackets, [], around a number. Since this string represents my column names for a SQL database I need to remove/replace them. So far I do it in the following way: It works fine, but it looks ugly for me since I have to do that for [1] to [20]. Is there a way to
How to declare sql variable in C#
My requirement is to remove all record but one from a table. For this I am executing a series of two different sql commands. Seems like on ssms it works fine but with C# is not –This is what I run …
Is there any function in C# like isnull in SQL?
In SQL server we can use “isnull” function for example if Table1 Contains Field1 and only one record which Field1 is null we can write this Query: which returns “0”. can we use any function like this in C#? for Example Consider textBox1 is Empty. and I want to Show “0”. Answer You can create an extension method: Sample Use:
Anonymous type result from sql query execution entity framework
I am using entity framework 5.0 with .net framework 4.0 code first approach. Now i know that i can run raw sql in entity framework by following It’s working perfectly but what I want is return anonymous results. For example I want only specific columns from student table like following It is not working. it gives exception The data reader
Incorrect syntax near the keyword ‘Table’ C# SQL [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 7 years ago. Improve this question Hello I’m trying to figure out why i have this error Incorrect syntax near the keyword ‘Table’. Thx in advance Code :