ADO.NET :: How To Call A Stored Procedures With Varchar Output Parameters In LINQ
Oct 15, 2010I have a stored procedure with the following structure:
[Code]....
I have a stored procedure with the following structure:
[Code]....
I have never used stored proc ouput parameters i want to know what is the use of using output parameters?If possible provide me some code.
View 10 RepliesI have several VB.NET functions which pass and receive values from executed stored procedures using parameters. However, the latest method I am using seems to be a little too specific on the datatype and data length of the parameters for my liking (i.e.
LogActivityCommand.Parameters.Add("@strErrSource", SqlDbType.NVarChar, 300).Value = strErrSource). For example:
[code]....
If I end up changing the datatype and data length properties of the variables in my SQL stored procedures in the future, I am going to have to re-visit my VB code too and alter the parameter settings here as well.
I have a stored procedure that works fine for classic asp, but how can I get my output parameters data back from in /MVC 2 / linq/ entities framework model . I have inported the function also, but when i try to code it i dont get results ...i know this is a matter of lack of / knowledge or exmple because i have been scouring the web for it and cannnot find into that accually works.
here is the stored proc.
[Code]....
Here was the one of the few tries I did:
[Code]....
but it executes fine does not give me an error, but also does not return the info i need to the viewmodel
I keep seeing stuff about "ref" on the net but "ref" shows " arbument # should not be passed with the ref keyword.
So i am not sure if there is a problem with the model, or with my understanding this, Now for your info I can do the same step with returning a dataset from a stored procedure fine, but I dont want a data set I just want excatly the data in the output parameters from the stored procedure.
how to pass the in out parameters in stored procedures
and how to execute it??
I have a asp.net web page.Inside i am calling 2 stored procedures.. which causes huge performance hit on the page
I need to call the both the procedures simultaniously using threading
Both procedures return data which will displayed on the page
Im new to ASP.NET (Normally use PHP), and im currently designing a website in VB.NET and SQL Server.
When using LINQ to SQL i know that it uses parametarized queries and we dont need to add them.
So do we need to use Stored Procedures in LINQ (for security reasons)???, If yes How
I'm totally new to MVC (started this morning), and am totally at a loss where to start. I need to rebuild an existing website. I already have a SQL Server 2005 database with tables and stored procedures. In the old version of the website, I built a function to call stored procedures and return the results as a datareader in VB.Net.
I want to use ASP.NET MVC with C#.
The first question I have is: Where would I put the code for the function that calls stored procedures ?
My second question is: Where do I go from there? I just need to get a sense of the basic way to handle presenting a dynamic website. I just want to start out with a Site.Master and display my menus which need to be generated dynamically from my database. I've been googling all day and I haven't really found any posts which answer all of my questions.
I'm using Linq to Sql to call some stored procedures for more complex work; is there any way Linq to Sql can tell me when the output columns from the stored procedure do not match the properties of my entity object? It seems that Linq to Sql tries its best to match the columns and ignores any mismatches.
View 8 RepliesI am using .net framework 3.5 and sql server 2008.
In my project coding, I want to call stored procedures in sql server 2008.
return value is the object list which references the entity.
But I have the questions.
If in the entity named as "order", is it matching the properties or created through entity constructor??
In my case, I have two properties and one constructor which match one property.
public class orders
{
orders ( string orderid)
{
this.orderid=orderid;
}
public string orderid {get;set;}
public string orderno{get;set;}
}
I am inserting records using stored procedures in LINQ to SQL in MVC.but i don't know the proper way.
View 1 Repliesi have a gridview and the delete option.
when i press delete button i want to run my stored procedure which requires an input variable. how can i do this?
I've recently inherited an ASP.NET 2.0 project from other developers and they have a LinqToSql datacontext with stored procedures. I've been asked to modify one of the SPs which is essentially just adding a couple columns to the database table and then those to parameters to the SP. So I delete the existing SP from the L2S context and drag in the new one with the additional fields, and all hell breaks loose. Suddenly I get over 20 errors! What seems to have occured is L2S has modified many other stored procedures that I haven't even touched and changed the return type from ISingleDefault<some object> to int. I've never used stored procedures before with L2S so I don't know if this is standard behavior or not. Does anyone know why this has happened and how to fix it to set the correct return type?
View 3 RepliesIve 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 ?
I have Linq-to-SQL DataContext and I run:
datacontext.CreateDatabase()
This works fine.
Recently I dragged a stored procedure onto the methods pane. I was thinking this stored procedure was now part of the datacontext and would get regenerated when creating the database.
ringht now i am working with one web page, in that page i have 3 sections of data [or 3 set of data] in 1 set 4 to 5 fields actions to be taken when we click on save button 1st it should save the 1st fields data in one of my sp and it should get the table level id it should loop that table level id into another set of records & insert into to the another sp
View 4 RepliesI have 2 page
1-index.aspx
2-House.aspx
And these are my table in database
1-House_menu Table
Id Name H_name
1 Sofa Furniture
2 Table Furniture
3 Iron Electric
4 Vacuum cleaner Electric
2-House_p Table that save users product information
Id Name H_name Subset Description
1 Couch Furniture House furniture Test1
2 Armchair Furniture House furniture Test2
3 Blender Electric Kitchen Test3
4 Oven Electric Kitchen Test4
I have 1 unorderlist menu in index.aspx
and 1 unorderlist in House.aspx page
I bind unorderlist from database
1-index.aspx
Bind repeater from House_menu Table
<li class="current">
<a href="House.aspx?H_name=all">Furniture</a> <ul>
<asp:Repeater ID="rptMenu" runat="server">
<ItemTemplate>
<li><a href="Houseaspx?H_name=<%#Eval("H_name") %>"><%#Eval("name") %></a> </li>
</ItemTemplate> </asp:Repeater> </ul> </li>
And in House.aspx page i bind repeater from HOuse_p table subset column
<ul> <asp:Repeater ID="rptMenuE" runat="server">
<ItemTemplate>
<li><a href="House.aspx?subset=<%#Eval("subset") %>">
<%#Eval("Subset") %></a> </li>
</ItemTemplate>
</asp:Repeater> </ul>
When users click on menu item in index.aspx menu it go to house.aspx and bind datalist according to H_name column from House_p table
This is code
private void GetCustomersPageWise(int pageIndex) {
{
if (Request.QueryString["H_name"] != "all") {
using (SqlCommand cmd = new SqlCommand("GetCustomersPageWise1", _cn)) {
string BehCode = Request.QueryString["H_name"];
[Code] ....
Now I want when users click on menu item in House.aspx page it bind datalist from House_p table according to Subset column .. How I can do it ?
If this is not the appropriate forum for this I didn't see any linq specific forum listed.
I am about to start a new project and I would like to use it as an opportunity to update myself with the newer technologies, like ajax and linq.
All my database CRUD operations will be done by sql stored procedures, does linq still make sense when doing that? I watched a couple introductory videos on linq and none of them dealt with stored procedures, thats why I'm wondering.
I like to use my own stored procs as much as possible.
That way I know exactly what's happening and I can explain and control things.
I'm using stored procs with LINQ to SQL for CRUD operations.
For select, insert and delete - using stored procs with LINQ to SQL is pretty straightforward.
However, if I want to use my own custom stored procs with L2S for updates what's the best way to accomplish this?
Can you provide some code that shows the best approach that you would personally choose for this?
I have been chasing this erorr all day and coming up blank. I created a stored proceudre(fairly complicated logic), added it to the context, and set the return type to a specific entity type.
It generated this:
[Function(Name="dbo.usp_ServiceTemplateSelectByFkID")]
public ISingleResult<ServiceTemplate> usp_ServiceTemplateSelectByFkID([Parameter(Name="FkId", DbType="Int")] System.Nullable<int> FkId)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), FkId);
return ((ISingleResult<ServiceTemplate>)(result.ReturnValue));
}
I call it from my service with the following method:
public ISingleResult<ServiceTemplate> GetByFkId(int FkId)
{
return Db.usp_ServiceTemplateSelectByFkId(FkId);
}
I have tested the stored procedure and it returns the results I want. When I make the service call from the controller, it doesn't error out, however, it should return 4 records in this instance and instead, it returns the same 4 records (repeating the first record 4 times).
In addition, in my controller code, I am using the MVCContrib ToPagedList() method which doesn't appear to work with the ISingleResult interface (forward only cursor, I'm guessing). I have attempted converting the service results to IQuery, List, and Array, however, I still have the problem with the first record being repeated 4 times.
I have a question. How do we define date output parameters for a stored procedure?
before you answer,I should mention that I am not referring to the sql syntax definition ,which is @mydate datetime output.
This is ok,what i am asking is HOW DO I SPECIFY IT IN LINQ WHEN I NEED TO CALL THE STORED PROCEDURE IN THE SERVER SIDE CODE. I am repeating that I do I am not referring to the sql definition .
I've modified an existing strored procedure. It originally had one ouput parameter in the stored proc and it was set up as follows in the c# code that called it:
cmd.Parameters.Add("@Var1Param", SqlDbType.BigInt);
if (Var1 == 0)
cmd.Parameters["@Var1"].Value = DBNull.Value;
else
cmd.Parameters["@Var"].Value = Var1;
cmd.Parameters["@Var1"].Direction = ParameterDirection.InputOutput;
cmd.ExecuteNonQuery();
// Get Var1
Var1= dataMorph.ToInt64(cmd.Parameters["@Var1"].Value.ToString());
Just to clarify, this parameter was declared as OUTPUT in the stored proc but as inputoutput in the C# code. This worked fine. I have added another parameter to the same stored procedure and I want to retrieve both from the C# code. The C# code now is as follows:.................................
I have a working controller for another stored procedure in the database, but I am trying to test another.
When I request the URL; http://host.com/Map?minLat=0&maxLat=50&minLng=0&maxLng=50
I get the following error message, which is understandable but I can't seem to find out why it occurs;
Procedure or function 'esp_GetPlacesWithinGeoSpan' expects parameter '@MinLat', which was not supplied.
This is the code I am using.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; [code].....
I have created a stored procedure shown below ,how will i call this from c# code behind to get the result and results are stored in dataset.
USE [Test]
GO
/****** Object: StoredProcedure [dbo].[tesproc] Script Date: 09/01/2010 13:00:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[tesproc]
-- Add the parameters for the stored procedure here
@a float, @b float, @c float,@d int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select Id, Name1,ZipCode,StreetName,StreetNumber,State1,Lat,Lng, ( 6371 * ACOS( COS( (@a/@b) ) * COS( (Lat/@b) ) * COS( ( Lng/@b ) - (@c/@b) ) + SIN( @a/@b ) * SIN( Lat/@b ) ) ) as distance from business_details where ( 6371 * ACOS( COS( (@a/@b) ) * COS( (Lat/@b) ) * COS( ( Lng/@b ) - (@c/@b) ) + SIN( @a/@b ) * SIN( Lat/@b ) ) )<@d
END
If i execute this stored procedure in sql server its working fine with this following call
exec dbo.tesproc 12.9216667 ,57.2958,77.591667,1
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