ADO.NET :: Inserting Records Using Stored Procedures In LINQ To SQL In MVC
Mar 11, 2011I am inserting records using stored procedures in LINQ to SQL in MVC.but i don't know the proper way.
View 1 RepliesI am inserting records using stored procedures in LINQ to SQL in MVC.but i don't know the proper way.
View 1 RepliesIm 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'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.
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 a stored procedure with the following structure:
[Code]....
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 am using Linq to SQL. I have a table with a uniqueidentifyer column.
I need to insert 1000 records, each with all the same values except for the uniqueid field.
I know the syntax to insert a single record for example where dc is a DataContext():
[Code]....
Does anyone know how if there is a way, other than looping 1000 times, to tell SQL to insert 1000 records generating different unique ids but assign the constant values to the other columns?
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 RepliesI am using Visual Studio 2008 and SQL Server 2008 and have added a SQL datasource to my form.
When I configure the datasource, I choose my connection string which looks like this in my webconfig:
<connectionStrings>
<add
name="PSFSPRD_ConnectionString"
connectionString="Data
The database I am using has a schema called EQB and as such, my stored procedures are named as EQB.usp_SelectFunds, EQB.usp_SelectAccount, etc.
On the select tab of the Configure Data Source screen, I choose to use a stored procedure. The dropdown shows my stored procedures, however, the schema name does not show up in front of the stored procedures in the drop down. I see only usp_SelectFunds, usp_SelectAccount, etc.
I select one of the stored procedures and when I click TEST, I get the message that the stored procedure is not found. If I instead choose to use a SQL statement instead on the configuration screen and enter EXEC EQB.usp_SelectFunds and click TEST, it works fine.
Why are my stored procedures not showing up correctly in the stored procedure drop down and how can I fix this?
We have an existing application with a mature database where most of the business logic is in Stored Procedures that are maintained by a separate department. Application developers are not given access to the database except via stored procedures.
I am looking for an example of calling stored procedures from within MVC.
Actually, we have done almost no development until now in ASP.Net at all. Is the difficulty in interacting with stored procedures a MVC problem or is it a more generic ASP.Net problem?
I used to be a software tester. I am a little bit familiar with stored procedures from client-server apps. My understanding is that they are on a server (where they operate more efficiently than if they were a module of code on a client machine) and they are used to modify the database.
Can anyone give me information a nutshell about stored procedures and when to use them?
I'm tyring to call stored procedures from asp.net C#.
Initially i created a stored procedure in mysql database which returns a whole table when executed.Bt i'm a bit confused on how to call the stored
procedure from c#.
I'm a novice @ asp.net and in fact any dynamic website building as I'm normally the dba behind the scenes, however, circumstances arise and now I'm looking at the front end, so forgive me if my question seems so obvious or badly worded, it's only day 2 of the .net environment for me.
I have a stored procedure with several parameters (11) that I have written & tested on the server.
I am trying to call it on a web form (using visual web developer 2008 express)
I have created the text boxes & drop downs on the form.
Added a gridview table connected to my stored procedure (which then works on testing) (parameters set to control & picked from the dropdown of form boxes to match).
there is also a submit button. (no coding added) just dragged on page.
Like i said when I test the connection for the gridview of the stored procedure it works, however on the web face it doesn't. I put in the parameters click the submit button and the screen refreshes, i get done @ the bottom but no results. I tried just using the sql and got the same result. I've looked at books but can't see what I'm missing, although, i suspect the onclick event of my submit button.
I've been working on an upgrade for an app that's currently online.
I copied the database to my development server, have been making upgrades to the db (new tables, additional stored procedures, functions, etc). The new upgraded db is now complete and ready to go back online. I developed a script for all the new tables as I created them.
Basically this new db will go with the new upgraded app at a new domain.
So my plan is this...
Copy my existing db (the original) over to the new server.Run the script I developed on my development server to upgrade the new db to the latest version. Take the original db offline once the new one is running. However when I developed the new sps and fcns I didn't script them like I did for the tables (ooops! not thinking), and I have about 100 new sps. Is there anyway to script all the sps in one hit, so that I can run one script to upgrade the new db?
Or do I have to script them individually?
Suppose you have to query a lot of tables and calculate some values and spit it out to the user. Is it ok to have all the business logic for this in the stored procedures? Or is it a better practice to return all the data to the application and do all the data manipulation and rolling up in there?
View 6 Replieswriting vb.net classes based on a MS Sql Stored procedure. So, here's my question.....Is there some kind of tool out there that will generate a class based on a stored procedure. So, for example, the tool can read a Stored Procedure like below:
[Code]....
I have a stored procedure which is working fine and also code in my vb class, which when I click on save, looks as though it has executed but no information is saved into the database....
My code used to save the data into the database is below.
[Code]....
I need to retrieve data from a stored procedure, but not from a reader. I need to insert and read to see if there is an error code returned so I can Display It
[Code]....
This inserts data into a stored procedure, since I have a promotion going on, I want to check to see if anyone has tried to create several accounts to try to be Customer #100 or so on, I have achieved this in the procedure, and set RETURN @ErrorCode = 1
Have I Set up the SqlParameter Correctly, or do I now have to declare a direction for each parameter?
I have had problems reading from Stored Procedures and Tutorials Seam Straightforward, but thay are about readers only not Input Output
i am calling stored procedure through entity model like result=ctx.spname(parmas), i am expecting 0 or 1 as a result after the execution of sp, but its returning unknown values like 178 for number records.
View 2 Replies