Access :: Insert Query Due To Database Relations

Jan 8, 2010

i have a problem executing an insert query. whenever i try to insert i have an exeption telling me it cant execute because a record needed in another table; where i select a value form that other table according a listbox, and then insert it into this table. here is a sample of my code:

OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|emp2.mdb");

int a = 0;
conn.Open();
string sqlcmd = "select id from nationality where descreption = '" + DropDownList1.Text + "'";
OleDbCommand readNatCmd = new OleDbCommand(sqlcmd, conn);
OleDbDataReader readerNat = readNatCmd.ExecuteReader();
while (readerNat.Read())
{
a = readerNat.GetInt32(0);
}
readerNat.Close();
conn.Close();
string saveEmpcmd = @"insert into employee " + "(nationality) " + "values (@nationality)";
OleDbCommand objCmd = new OleDbCommand(saveEmpcmd, conn);
objCmd.Parameters.AddWithValue("@nationality", a);
conn.Open();
objCmd.ExecuteNonQuery();
conn.Close();

now, the form executes with no errors, but it catches an exeption caused by the ExecuteNonQuery funtion; here it is in details:

System.Data.OleDb.OleDbException: You cannot add or change a record because a related record is required in table 'nationality'. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at Default2.Button1_Click(Object sender, EventArgs e) in c:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005WebSitesempDefault2.aspx.cs:line 305

when i remove the relation between the tables, the exeption isnt catched anymore, but the value stored in the employee table is 0 how can i solve this?

View 6 Replies


Similar Messages:

Just Need Some Basic Functionality Like Update,delete, Insert, Simple Constraints And Relations?

Feb 17, 2010

Is there some kind of simple database system that uses simple text or xml files for data storage? I just need some basic functionality like update,delete, insert, simple constraints and relations.For the project that I have now using SQL Server would be too heavyweight and I have never really liked it anyway.

View 6 Replies

Access :: IIS_WPG Write/modify Access To The Folder Where MS-Access Database Is Located - Insert An Error Pop-up?

Feb 17, 2010

Is there anything missing in IIS 6.0 that prevents me from (Insert into table) using MS-Access?

Explain: The application works fine under Visual Studio 2008 IDE the insert into table works fine with no error, Also I tested with hosting provider and works fine with no problem. but now I have published the same exact app in a dedicated server windows 2003 with
IIS 6.0 .NET framework 2.0 with latest service pack I gave IIS_WPG write/modify access to the folder where MS-Access database is located and database but at the time of insert an error pop-up. I need to install in the Server or settings in the IIS to recognize my MS-Access db is it some office runtime that I am missing. (BTW I am using OLEDB connection string in my C# )

Using System.Data.OleDb;

I can retrieve data off of it with no problem but when I try to insert is when it fails I thought the problem was Access Rights but I do not think is the case.

View 4 Replies

DataSource Controls :: Cannot Access A Disposed Object When Handling Foreign Key Relations?

May 15, 2010

i am currently working on an asp.net mvc 2 web app using LinqToSQL. I would like to handle a scenario where a user comes form a country and for this i have set the users - countries db relationship and in my user model i have a CountryId property.

I would like to display the country name on my users display view, so i tried fetching the country name like this: User.Country.Name, but an exception occurs that i cannot access a disposed object. I understand that this is caused by the way i handle my users repository and service.

This the repository users code:

[Code]....

This is the service users code (the repository is not class level property, but a local one that gets dipsosed immediately after calling it):

[Code]....

So, how could i handle such a scenario, where i would like the Country model to be also fetched in order to use it later? Should i convert the repository model a class level proprty in order not to get disposed?

View 3 Replies

Access :: Data Type Mismatch While Inserting Into A Number Field In An Access Database Using A Parameterized Query?

Jun 9, 2010

I have a data type mismatch while inserting into a number field in an access database using a parameterized query.I think this should be pretty simple but I am still learning a lot.

[Code]....

I have some commented out as I am working one field at a time. The working fields are textboxes and the non working ones are dropdown lists. But I think it may be the field that the list is drawing from? Not sure.

View 2 Replies

Access :: Unable To Insert Data Into Access Database Using OLEDB

Sep 2, 2010

I have a form wilh couple of Drop downs and text boxes and a Data Grid View which displays data from Access Table. When I hit add button on the form, I can see the data being added to the Grid View. But when I close the form and open the Access Database File (.mdb), the respective table is empty. The Access Table is not being updated. Second time if I open the form, the Grid View is also empty.I am pasting my code here.

Public Class Home
Shared OleDbConnection As System.Data.OleDb.OleDbConnection
Shared ExpensesDataAdapter As System.Data.OleDb.OleDbDataAdapter [code]....

View 4 Replies

Access :: Could Not Able To Insert Record Into The Table - Operation Must Use An Updateable Query?

Mar 23, 2010

This is the first time i am using ms access database for the c# asp.net .

I am getting the following error when i try to insert the record.

Operation must use an updateable query.

[code]....

View 2 Replies

Access :: Using The Code To Insert Data Into An Access Database?

Mar 23, 2010

I am using the following code to insert data into an Access Database. Also this is the sqlcommand.

UPDATE TASKS Set Notes="bunch of html code" WHERE APPLICATION="SomeApp"

However I get an error. How can I input data regardless of what is in the command area?

'Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|AddCol.mdb"

View 3 Replies

Web Forms :: Writing A Log In Xml File Or Insert Query In Database?

Feb 20, 2010

i want to maintain a log of the visitors for a website.. the number of visitors is fix approximate (800), but i have to maintain the record of each visit page wise like page Id, time visited, user id. i am doing it using a database as it was .

i was asked to use a insert query on every page ,(ie each time user visits a page write the log to database), but i dint like the idea.. of making server trips every time the user visits a page and also we have a seperate database server. I had a idea of using XML.. but which is the best way performance wise writing a log in Xml file or insert query in database?

View 4 Replies

Access :: Database SQL Query Between Two Dates Datagrid?

Aug 25, 2010

where I'm going wrong with this SQL Query of an Access Database which populates a Datagrid,

From a calendar selection the user can select a From and To Date and I want the SQL Query to ONLY pick up the dates between these two values, the selection is fine it seems to be the sql query which is the problem ... (I have added dates rather than the text value to make it easier to get working ) the following query wil pick up dates outside of the selected values 01/08/2010 , 02/08/2010, etc

SELECT COUNT(*) AS Date_Installed, Date_Installed AS Expr1, Installed_By FROM Buildprocess WHERE (Date_Installed BETWEEN '20/08/2010' AND ' 25/08/2010') GROUP BY Date_Installed, Installed_By

View 17 Replies

Access :: Insert Autonumber Values Into Database?

Jan 4, 2010

Imports System.Data

Imports System.Data.OleDb

Partial Class _Default [code]...

in my database table has four field as follws firstname, lastname, User_id and serial no as (Autonumber as well as PK) i am able to insert first 3 values by insert query as above but, insert autonumber data type mismatch.

View 2 Replies

Access :: Create A Simple Web Form To Query Database?

Jun 8, 2010

I'm new here and really, new to asp.net except the very basic things.

I am trying to create a very simple (I think simple) web form with five textboxes and three dropdown boxes and one submit button. The user enters information in the textbox fields and selects from the dropdown lists (which are populated from the database), hits enter and the database runs the query and returns information on a separate page (or can it return to the same page via panels?) The original page returned to a separate page using server transfer.

I have this page already existing in asp but feel that it would be much better served in asp.net.

Can someone point me to a post where I would guess this has been answered many times?

How do I submit the new data to the database, update the records and return the query?

View 2 Replies

Access :: How To Insert Data Into Database From Html Page

Mar 30, 2010

i am newer to the developement industry..i created one html page for entering purchase details. i am using MS access as

database. but i don't know how to connect html page with access data base and how to insert data from html page..so i am asking all of your support in this problem.

View 7 Replies

Web Forms :: Insert Date From Textbox Into Access Database Table?

Dec 31, 2010

[Code]....

I am sure this has been covered many times but I can not find what I am looking for and I am sure it is simple.

I am trying to insert into an access database table a date taken from a calendar control or a textbox that the calendar control writes to.

Currently I am getting a "datatype Mismatch" error.

View 6 Replies

Access :: Access Database - Update Record Or Insert New Record?

Jun 27, 2010

I have written a script to write several values to an Access Database Table, but I need to ammend i so it checks for two values (Asset and LName) to see if they match if they do it updates the record if not it writes a new record, my script so far is as follows :

[Code]....

I'm just stuck as I can't work out the best way to do it,

View 17 Replies

Access :: Insert A Record The Filing Date And Report Time Fields Are Always Blank In The Database?

Sep 2, 2010

When I try to insert a record the Filing Date and Report Time fields are always blank in the database.

View 5 Replies

Forms Data Controls :: Access Data That Is Outside A DataList And Insert It Into A Database?

Feb 2, 2010

I can't seem to access a label that is outside the DataList. I wish to add the data in the label into a database, aswell as data that is inside the datalist (this is already working though). My SQL-query with only the specific label looks like this at the moment:

[Code]....

The data is added to the database when pressing a button inside the datalist (using onItemCommand). If I write UserIDLabel.Text the regular way it doesn't work either. The label is in the MasterPage, while the datalist is in a .aspx-page. If it is possible to somehow access the data that is in this label and add it to the database I would be ever grateful. Or is it somehow possible to add data that is in a Session and add it to the database?

View 3 Replies

Access :: Insert Not Working - Adding Additional Parameters To Insert From DetailsView

Jul 13, 2010

Getting the message that ObjectDataSource ... count not find a non-generic method ... that has parameters ... The parameter list is fine until I get to the very end and it list the two data fields that are in my DetailsView. Using the ASP Tutorial #17 (Examining the Events Associated with Inserting, Updating, and Deleting) and the Exploring the Data Modification - specifically the one showing the INSERT of the Product Name and UnitPrice. ASPX page is pretty simple and attempting something similar, two fields to insert a new record - update the other fields later.

Full Error Message follows along with ASPX and the AsignaturasBLL.cs. Interesting thing is that when I swap the two fields in the DetailView, then the last two fields in the error message are swapped. In the error message I bolded these two fields.

[Code]....

View 6 Replies

C# - Deleting Selected Relations In Many-to-many Relationship In EF?

Mar 13, 2011

In SQL, I have:[Bands] 1 ---- * [BandsGenres] * ---- 1 [Genres]In my EF layer, it translates to:[Bands] * ---- * [Genres](BandsGenres is BandId and GenreId)My problem is, I can't seem to figure out how to delete just the selected relationships I need. Basically, I'm trying to update a list of type Genre for a band. A list of Guids is passed in and I'm able to get those using joins. However, the .Remove() method isn't removing the old genres and adding the new ones. I tried using .Attach(g) and .DeleteObject(g) but that removed the actual Genre (from Genres) instead of just the relationship.

[code]...

How can I delete/add or update my list of genre relationships for a band, given a list of genre IDs?

View 1 Replies

ADO.NET :: Syntax Error In Insert Into Statement / Trying To Insert Data Into Access Db

Aug 4, 2010

i am new to asp.net programming i am trying to insert data into access db from asp.net web form but it is showing error as

Syntax error in INSERT INTO statement.
my code is :

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

View 5 Replies

C# - Modify XML File With A Dataset And Child Relations?

Mar 14, 2011

I want to modify an existing XML-File.

I used a DataSet to load the XML File with the ReadXml method.

I then displayed the relevant entries via the GetChildRows method.

I want to change/add/delete those ChildRows:

How can I accomplish this?

Below is the xml before edit

[code]....

View 1 Replies

Access :: Query Input Must Contain At Least One Table Or Query?

Jan 21, 2010

why I get the following error: Query input must contain at least one table or query

for this code...

Insert into BlogPost (BlogID,BlogTitle,BlogContent,Attatchments,IsEnabled,IsVisible) values

((SELECT BLOGID FROM Blog WHERE BlogOwnerID =7),'test','aaaaa','aaaa',true,true);

all i know that it is a problem with how i have nested the select statement...

View 1 Replies

Access :: Query In MS Access. Display Output Table In Visual Studio 2008?

Mar 25, 2010

Can a query output made in MS ACCESS be accessed as a database in Visual Studio 2008?

I have a Parent and Child Table in MS Access with a one-to-many relationship. I created a query in Access that would produce a result table and I want the contents of this Query to be displayed in a Data Grid in Visual Studio 2008.

View 11 Replies

Access :: Linking Of Ms Access Db With Web Application(Syntax Error In String In Query Express)

Jun 7, 2010

i am new to asp.net programming i am trying to connect asp.net web application with ms access 2007 database. i have taken with two text boxes and when i enter some data in it and press submit button the data must load in access db i created with same fields.

my code is :

[code]....

Syntax error in string in query expression what is the correct way of inserting data into access db and what is the Syntax error in string in query expression.

View 3 Replies

Access :: How To Check Duplicate In Form View Insert Before Inserting In MS ACCESS

Aug 21, 2010

I want to Check Gr #(PK) of student wheter exist in table or not id exist show Msg in Label after lost focus from text box .. I tried AutoNumber in Access but it showing error while insertion
Note : im using form View control for insertion...

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved