MVC - Getting Started With Linq And SQL Procedure
Mar 3, 2010
Today is my first day using ASP.NET MVC, and I'm finding it very intriguing. I only just started learning asp.net.
So basically I'm trying to call a procedure from an MSSQL database, and with it I need to send a paramater "PlaceID", which is an integer. This procedure basically just picks out a number of columns from different tables in the database. Here is the Linq to SQL code
The ultimate goal is to be able to retrieve all the information and return it as JSON with a function that will be available for a javascript.
I'm wondering what is the best way to proceed from here. I know I have to create a view, but I'm still unclear exactly on how I can call the procedure and make it store all the information. I could really use some help on this, some code examples would be excellent. I already wrote a C#.net function to convert a datatable to JSON using a stringbuilder, but I get the feeling there is a smarter way to do things.
View 1 Replies
Similar Messages:
Feb 15, 2010
I am trying to re-write an existing asp.net website using MVC with Linq to SQL. A page we have is used to insert new contracts and uses usp_contract_insert to insert a new contract into t_contract as well as t_project. On my dbml file i have dragged t_contract on and then I try to drag usp_contract_insert on top of that and I get the error :- Microsoft Visual Studio
One or more selected database objects return a schema that does not match the schema of the target data class. Nothing has been added to the designer. The stored procedure returns the id of the last project which was inserted. I don't quite follow this and unsure how to go about hooking my Controller up using Linq to SQL to call this stored procedure
View 7 Replies
Jan 28, 2011
I am using LINQ to SQL for inserting, updating my DB now i am using stored procedures to do the same,but i dint find any advantages or less code in using stored proc what is the main diff between using stored proc and not using stored proc?
View 1 Replies
Feb 16, 2011
I am inserting records using stored procedures in LINQ to SQL but i am getting an error at empid
[Code]....
i am getting error like Table 'emp' does not have the identity property. Cannot perform SET operation.how to solve this??
View 1 Replies
Feb 25, 2011
I am trying to execute a stored procedure in LINQ. When run in SQL Server it returns several fields, mostly integer and float fields. But when I call the stored procedure in LINQ, all it returns is 0. Here is how I am calling the stored procedure :
[Code]....
And here is the stored procedure :
[Code]....
View 3 Replies
Mar 31, 2011
I am new to Linq server.I have a stored procedure in my databse that retuens count number.
select COUNT(*) from tbl_WorkerUsers
where WorkerCode=@Wcode
when I run it directly in my database it returns 1.
exec checkWorkerCodeAvailibility 100000312
but when I run it in c# code it always returns null.
WorkerDataContext Wkc = new WorkerDataContext();
int? result = Wkc.checkWorkerCodeAvailibility(Int32.Parse(Wcode)).Single().Column1;
View 1 Replies
Jan 30, 2011
i am using stored proc in linq to sql but i have done insert & delete operations but im unable to do the select operation i have tried but no use,whenever i enter the id into the textbox it should display the record?
View 5 Replies
Aug 3, 2010
i have this procedure:
[Code]....
the difficulties are the follows:
1)i cannot know how to execute stored procedure with LINQ
2)how can i set value to my properties after a selection?
3)how can i set optional parameters in a stored procedure by LINQ?
View 1 Replies
Mar 5, 2011
I have function like
Public Dataset getdata() {
dataset = db.prcGetdata("name");
return dataset; }
db is linq. prcGetdata is a proc which accepts name param and returns 1 or more rows. So, my requirement is how to get data to dataset using linq.
View 3 Replies
Jan 29, 2011
I am working on LINQ. I am calling a SQL Stored Procedure with 2-3 parameters it's working fine. When i am going to call Stored Procedure with 8 to 9 parameters the auto generated column is not comming automatically. So i am unable to use LINQ with Stored Procedure with multiple parameters.
View 4 Replies
Dec 18, 2010
i have create the object of
1 dataclassContext obj=new dataclassContext();
2 now i call the updateProc
int row=ob.MyupdateProc(QuestionID,peronID);
if(row>0)
{
do some thing
}
but row always retrun 0 even procdure do update in database
View 1 Replies
Mar 2, 2010
I have created one stored Procedure as
[code]...
I am not getting the result with extra column c.I am not getting what is the Problem.In sql server,It's working fine.
View 2 Replies
Feb 12, 2010
Is it posible to run a stored procedure using linq? I dont mean one that returns a table i just mean one that runs a set of transactions exec sp_MyProc @Var or something?
View 1 Replies
Jan 18, 2011
i do have a stored procedure which inserts data and the message should be displayed that data has been sucessfully updated or not
[code]....
View 8 Replies
Aug 18, 2010
I'm executing an update stored procedure from LINQ to SQL and I need to know the records affected after the update is called. I'm using dbml designer to generate the LINQ code.
View 4 Replies
Sep 8, 2010
Using asp.net MVC in c#, I am making a call to a stored procedure using Linq into my SQL Members table. I have no internal caching on the application, already checked to make sure it is turned off.
Test case:I have my username set to test1. From the website I change my username to test2. The website still shows test1. I go to Management Studio and run my stored procedure called MemberByEmail, it shows test2 correctly.I start simple, refresh my page to see if it's browser cache, still test1. I go to debugging and walk through the code and find that it goes correctly all the way to here to call the database:
/// <summary>Method that is mapped to the dbo.MemberByEmail database procedure.</summary>
/// <returns></returns>
[System.Data.Linq.Mapping.Function(Name="dbo.MemberByEmail")][code]...
Again I ran the stored procedure through Management Studio, and it came up with test2 as the username. I waited for 15 minutes, refreshing the web page every 5 or so, and it never cleared and served the correct test2 from the db. The last strange piece, I ran IISReset and refreshed the page, test2 was returned.
UPDATE: I created a console application to take out the web piece of it. The problem is the same when accessing directly from a console app also, no change.
View 2 Replies
May 7, 2015
I have procedure near below i want to call this procedure through "linq"
I use  mvc 4 and .edmx
//table//
CREATE TABLE [dbo].[Board](
[BoardID] [uniqueidentifier] NOT NULL,
[Board] [varchar](50) NOT NULL
) ON [PRIMARY]
GO
//Procedure //
create procedure [dbo].[GetAllBoard]
as
select * from Board order by Board
View 1 Replies
Feb 7, 2010
I am having problems returning a string value through a stored procedure/linq to a label. Everything works fine if I return an integer value but I cant get a string value to bind to a label. I get the error message
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value,
NumberFormatInfo NumberFormat) +201
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +66
[InvalidCastException: String "System.Data.Linq.SqlClient.SqlPr" to 'Integer' is invalid‚]
This is the stored procedure
ALTER PROCEDURE test
AS
Select ProductName
From Products
This is the vb page
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim db As New DataClassesDataContext
Dim product As Integer = db.test.ToString
Label1.Text = product
End Sub
This is the aspx page
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</form>
View 1 Replies
Jan 6, 2011
I have a stored procedure that receives 2 parameters and returns 3 columns.
Here is how I added the SP:
1. Added SP to entity model (.edmx) via update model from DB.
2. Did a Function Import -- selected my SP, clicked "Get Column Information" and then created a new complex type (myStoredProcedureName_Result) which I assigned.
3. My LINQ is the following:
[Code]....
View 3 Replies
Feb 4, 2011
In my app I am using the open xml sdk to generate a word document and write the file to the response.output stream for the user to download.
At the time that the letter is generated I also need to call a SP via linq data context to update a row in my db.
I think that I need to execute this SP in a seperate thread so that I can simultaneouly write the file to the output. my method looks like this...
protected void btnPrint_Click(object sender, EventArge e)
{
//call sp to update
//create letter and send to client
}
Is this feasible or should I avoid seperate threads?
View 1 Replies
Feb 23, 2010
I have an application where depending on what the user selects run a different stored procedure.
I am using LINQ and am passing the stored procedure name into a sub that will run the stored procedure and return values that I am loading into a DDL.
For example I want to pass the procedure name "GetProducts_Hats" to the sub and not hardcode it.
Protected Sub LoadParamDropDowns(
ByVal SqlObjToExec
As
String )
I am passing the storedprocedure name in parameter SqlObjToExec
so instead of
values = mydb.GetProducts_Hats
I want to code it to be a variable
values = mydb.SqlObjToExec
But the above code does not work.
View 7 Replies
Jun 21, 2010
I can return single integer values when using stored procedures with Linq but I cant get single string values returned.
View 2 Replies
Jan 31, 2010
I started learning LINQ, So i thought of just creating gridview with sorting and paging using objectdatasource using LINQ. So i got this link
[URL] which Brian Orrel tell us how to do using IQueryable Interface. but i have nearly 300 lines of stored procedure which joins nearly 20 tables. so i thought of creating a stored procedure and using that instead of IQuerytable.
[code]...
View 7 Replies
Feb 25, 2016
I have a table and i want to use this table in asp.net page
how i will call the stored procedure on the basis
of Stored procedure's Action .
Â
CREATE TABLE Std_Enquiry(
StdID int IDENTITY(1,1) PRIMARY KEY CLUSTERED ,
FirstName varchar(50) ,
LastName varchar(50) ,
[Code].....
View 1 Replies
Dec 18, 2010
I always have this problem returning an out parameter from sql server using linq. So I have to use other means may be dataset. The following is the stored procedure: ALTER PROCEDURE [dbo].[InsertIntoTestProfile]
View 3 Replies