I've got 2 tables where each has a primary key which is also the identifier (Both fields called "id" in each table) In the "picture" table as one of the fields I've got the photoalbumid (The id of the "photoalbum" table). This field is just an int field. I'm getting the following error: "Cannot insert explicit value for identity column in table 'Picture' when IDENTITY_INSERT is set to OFF" Can anyone give me some advise? It's such a basic thing I would hope that there's just something small in the creation of the database that I've missed out. Let me know if you need more info.
the identity of the column is set to the maximum value. can i aviod this.
consider the following scenario,
my table has 2 rows as follows
id, name comm 1, John, 232.43 2, Alex, 353.52
now using the above code, when i insert 10, Smith, 334.23
as per the above link, sql server automatically sets the identity to 10. so for newly inserted records(without using identity_insert on), id automatically starts with 11.
i want the identity value to be 3, after using identity_insert on/off
Client -------------- ClientID -> PK FistName LastName AddressID -> FK to Address.AddressID
and
Address -------------- AdressID -> PK City CityCode
I created an initial set of address so
0 - London - 1000 1 - Paris - 2000 2 - Madrid - 3000 3 - Lisbon - 4000
I'm using Visual Studio 2008 with MVC. Framwork to use ADO.NET to create the model
My view is:
[Code]....
My model is just: ... Private _dataModel As New just2testDBEntities [Code]....
When post it retun erro
{"Can not insert the value NULL into column 'City', table 'dbo.Address'; column does not allow nulls. INSERT fails. ... statement terminated."}What I was intended to do is to insert a client and not a client and an address.
I have two tables one named article and the other article_type, where the articles table have a foreign key column that references the article_type primary table named "article_status". so i change the name of the article_status foreign key to be article_status_id, but now each time i tried to delete an article type column it raised an error said the the article_status column cannot be found , although i did not mentioned that column in my code here is the full error :-
System.Data.SqlClient.SqlException was unhandled by user code Message=Invalid column name 'Article_status'. Source=.Net SqlClient Data Provider ErrorCode=-2146232060 LineNumber=1 Number=207 Procedure="" Server=\.pipeE97065CB-CF67-4B sqlquery State=1 StackTrace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader() at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) at System.Data.Linq.SqlClient.SqlProvider.CompiledQuery.Execute(IProvider provider, Object[] arguments) at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.ExecuteKeyQuery(Object[] keyValues) at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.Execute(Object instance) at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.DeferredSource.GetEnumerator() at System.Data.Linq.EntitySet`1.Load() at System.Data.Linq.EntitySet`1.get_Count() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at System.Data.Linq.Table`1.DeleteAllOnSubmit[TSubEntity](IEnumerable`1 entities) at ProfessionalNetworkWebApplication.Models.ProfessionalNetworkRepository.Delete(Article_Type article) in C:UsersUserdocumentsvisual studio 2010ProjectsProfessionalNetworkWebApplicationProfessionalNetworkWebApplicationModelsProfessionalNetworkRepository.cs:line 35 at ProfessionalNetworkWebApplication.Controllers.ArticleTypeController.Delete(Int32 id, String confirmButton) in C:UsersUserdocumentsvisual studio 2010ProjectsProfessionalNetworkWebApplicationProfessionalNetworkWebApplicationControllersArticleTypeController.cs:line 73 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) InnerException:
1 - Is it necessary to have foreign key to obtain a Relation in Entity Framework between each entity.? 2 - I have a Language Table and many many table with a foreign key related to the language table. Is it right to add this foreign key or I should do something else ? Ex: Language LangID LangName
I am trying to use the TableApapterManager.UpdateAll to insert values to master and child table. I had set the relation to cascade for update in the dataset and the HierarchicalUpdate to true. But stil when I run TableApapterManager.UpdateAll(dataset), I get a foriegn key violation error. Following is the code I used:
The error I get is "The INSERT statement conflicted with the FOREIGN KEY constraint "FK_MemPhones_Members". The conflict occurred in database "Family", table "dbo.Members", column 'i_memeberid'. The statement has been terminated."
I have coded my application to send mail and it works fine some of the time depending on the to or from address specified in the particular message but at other times I am getting a relay error.
"The server will not relay mail for foreign domains".
I HAVE authenticated myself to the mail server using a valid username and password in the code.Basically here is the setup. Our site is hosted overseas in the states with one company, our nameservers are also in the states but with our company not the hosting company. Our mail server is local (that is here in New Zealand). I'm pretty sure that the code is right because I've read dozens of posts on here which point to coding errors and it seems to be right.
Do I need MX records or anything like that in some place?
I had table had data about product photos and this table had a relation to product table and product may be has more than Image. I did my code well to get all images for product by productID query string but only first image retrieved. Note that ProductID in handler page is a foreign key into the Photobank images table, also I note that productID had value of ID table didnot the productID:
stored proc:
ALTER proc [dbo].[SP_GetPhotoBank] ( @ProductID Int ) as
Lets say there's a table Table1 with Primary key as "MainID" and this MainID is being used as a Foreign key in many tables.
Now when I try and delete a record from Table1 who's MainID as foreign key is being used in some child tables, then it throws this exception that "Foreign key conflict n stuff"..
Now I want to design my Delete Strored procedure in such a way that first of all checks ALL the child t ables that have that foreign key column "MainID" and if MainID from Table1 is being used in any of the child tables it should return 0 . Based on this 0 value I want an alert box to show that will say "Still in use or watever" and wont let the user delete that record unless ALL the records in child tables have been deleted that were using that mainID from table1.
I can't use ON DELETE CASCADE. I want the user to delete child table records manually one by one. Only after child table records using the MainID have been deleted that the user can delete record from Table1
I am trying to build the MVC Music Store from ASP.Net, my only problem is that the tutorial is made for asp.net 4.0 C# and mvc2 an i am creating it with asp.net 3.5 VB mvc 1. For now i found out a lot of thing wich will work much better in the new frameworks, but my webhost still doesnt support it, because they have some problemms with PLESK.
Now i have a problem i cant figure out, i cant update data from a dropdown list, in the database using the updatemodel, that are foreign keys. Just all other data wich are not foreign keys and primary keys are updateable. These are automaticly created in the sql entity model.
when i do currentCustomer. In the drop down I can see all the columns listed except one column which is a foriegn key from order table , how do i insert into intorder_fk
I dont have primary key for Compaign Table CompaignId is Identity column. Now i want to use CompaignId in Employee Table because based on compaign user will retrieve employee data in Front end. Again Employee table doesn't have primary key. I am uploading excel file data to databse but in excel file there is no empNo so i cannot use primaryKey i have EmpName in excel file. How to solve this issue. How to use master table if possible create table structure for my requirements.
So I am working with a database and am trying to get my model code working.I have a situation where I have a table called accounts that for simplicity has 3 columns
accountid, accounttype, parentid
basically its a parent child relationship. if parentid is null its a parent, its not its a child of the accountid.Im running into problems getting the .edmx file mapping. parentid is a foriegn key on the table.
how can access the parentid column? i can see it in account navigation account1 but Im not sure how to get access to it in my linq query
As i start to work with MVC simple things are not so simple. I have a view that renders correctly a single table of my Database (using Entitry framework created automatically by visual from my SQL database).The table show everything including the foreign key and i i seeking for replacing the foreign key by a friendly name of my foreign table.In the controleur i have the following code :
public ActionResult Index()"Equipement"] = new SelectList(_entities.T_E_EQUIPEMENTS_RESEAU_EQP.ToList(), "EQP_ID", "EQP_NOM"); return View(_entities.T_E_CONSOMMATEURS_CSO.ToList());
both table are joined by the foreign key CSO_EQP_ID and the primary key EQP_IDI have no clue of what to define in the view ?Any exemple of this simple need will be welcome.
I have an MVC3 with EF4 project. I have a screen for order .Order has 2 id's inside it for Billilng and Shipping AddressID .When I go and create a new order these fields render as single textboxes as Ids'Question is how can I render full address textboxes (addressline1,city,state,zip etc) do I have drop in the html markup for them? In that case while capturing the data back I willl have to go with classic way of retrieving name/value pair and then do insert into address bring back that identity and update the order record...?
Create(int customerID,FormCollection fc){}
So the main question is how can I do ModelBinding with foreign keys?
I have two tables, which is table 'A' and table 'B'. Table B contains a foreign key that is referenced to table 'A'. The question now is, could I used an option in my project in visual studio an 'Others specify'? I believed that it's not possible, isn't it?If I have a selection that is bound to a datasource then is it possible to make an option 'Others specify' without adding the specified value to the database, which in turn would not have a unique ID? Table B contains the table A ID PK field, and all values from table A to table B should contain a unique ID.
I m try to insert record to table, its working well without foreignkey using Entity model. But i need to insert foreign key. I used the following query, its not working well via Entity model.
objFacility.FacilityCategoryReference.EntityKey = new System.Data.EntityKey("testEntities.test", "id", 10);
I am using Access 2003 Database and I need to retrieve list of a table's foreign keys and tables they are related to in C#. I used GetSchema() function of OleDbConnection as well as OdbcConnection classes. But It just returns the name of key among few other details.
I am new to sql. I got this task to design a table in sql. It has for columns user_ID(PK, FK1) , WebSite_ID (PK, FK2), Create_Dt, Update_Dt How do I create PK and Fk1 and PK FK2 in sql server 2008 R2