Writing To A Relationship Based Table?

Feb 15, 2010

I think I'm just after advice on best practice with this! I have a database which has 2 tables. The first table has ID, Name, Address and the second table has ID and JobType. Table 02 can list multiple types of JobType so we could have

Table01:

1. D Smith. Address01
2. S.Jones. Address02

Table02

1. Accounts
1. Sales Ledger
1. Chartered Accountant
2. IT
2. Web Design
2. Graphic Design
2. 1st line support

A join gets them together and all works perfectly.However, the content will be updated when some one fills in a web form. Do get the form to send results to both tables, I assume I have to open the database twice or can I open it once and open each table one at a time? I know I could practice this and not ask the question but I am interested to know what is the most efficient way. I would also need to know what ID to use. So when I populate Table02 it uses the correct ID from Table01. At the moment Table01 ID field is incremented automatically. Would you suggest I always assign the ID myself, or would I need to query the database, find out what ID number is currently in use and then increment it by 1 and assign the new number to an ID variable which then populates the Table's Field? In which case, am I opening the database again or trying to perform all 2/3 stages in one go?

View 3 Replies


Similar Messages:

C# - Order A List Of Entities Based On A Field From A Separate Entity With A Relationship

Mar 6, 2011

I'm using Entity Framework for my object-relational mapping, and jqGrid for my grid.

I have an Employee entity, that contains a ContactID field. I have a Contact entity that contains fields FirstName and LastName.

I want to display a list of Employees in a grid, and give the user the ability to sort by FirstName and LastName.

Here's what I have right now:

public JsonResult GridData(string sidx, string sord, int page, int rows)
{
var pageIndex = Convert.ToInt32(page) - 1;
var pageSize = rows;
var totalRecords = GetAllEmployees().Count();
var totalPages = (int)Math.Ceiling(totalRecords / (float)pageSize);
IQueryable<Employee> employees = GetAllEmployees().
OrderBy(sidx + " " + sord).
Skip(pageIndex * pageSize).
Take(pageSize).ToArray();
}

As you can see, this only gives me the ability to sort by fields in the Employee entity, so I can't sort by FirstName and LastName.

How can I modify this to accomplish that?

View 1 Replies

DataSource Controls :: Many To Many Relationship - Table Location?

Apr 18, 2010

I working on website and i have ready database from the company database. I have a table Location has only two fields : city andtate.I tried to get select the * city where state = something , but i think it is wrong,Is it a Many-to-Many realtionship

View 4 Replies

Security :: Relationship Between Membership Provider And Table?

Jun 26, 2010

I have my membership provider configured and working on my web host.

IŽd like to create a table, for example, table ARTICLES, and iŽd like that the user logged in, his ID or his NAME, was inserted into my ARTICLES database.Which one is the best table i could get for doing that ?

I was checking the table aspnet_users, but its Primary Key has a uniqueidentifer type.This wonŽt be a problem in the future ?Or is there a better way to relate my table with the membership provider ? Maybe another table OR another field.

View 1 Replies

SQL Server :: Create A Relationship Between Database Table And Xml File?

Mar 17, 2011

I've just taken over looking after a website and well to be honest the way it's been put together is not the best, but I have to make do as the client does not have the money to make major changes.Anyway currently there is data stored in a MsSQL database and some in an XML file. The xml file does have a ContentID attribute which matches the ContentID in a table.Not really done much with XML as I tend to use a database and LINQ.What would be the best way to tie these two together so I could output the results in a gridview for example.

View 2 Replies

SQL Server :: Relationship Which Allows NULL Entry / Error 'FK_Table_Contracts_Table2_PONo' On Table 'Table_Contracts'?

Nov 29, 2010

I have two tables as below.

I tried to establish a relation between two tables in such a way that Table_Contracts will still accept NULL values for [PO_No], but [PO_No] on TableContract will be automatically updated when [PO_No] on Table2_PONo changed. Moreover, if you want to delete a record on Table2_PONo, it needs to be stopped if there is a related data in Table_Contracts.

I set a relation with these parameters:

Check existing data on creation or re-enabling>
No

Enforce for replication>
No

Enforce foreign key constraint>
No

Delete Rule>
No Action

Update Rule>
Cascade

I got this error

Introducing FOREIGN KEY constraint 'FK_Table_Contracts_Table2_PONo' on table 'Table_Contracts' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

Table2_PONo
[PO_No]
(primary key)
[Project_ID]
[SupplierID]
[Description]
[TotalPrice]
[PO_Currency]
[VATpercent]
[CostCode]
[Notes]
[PO_Date]
[Reality]
[UpdatedBy]
[FromAccess]
Table_Contracts
[ContractID]
[ProjectID]
[PO_No]
(accepts null values)
[ContractNo]
[ContractDate]
[ContractValue_woVAT]
[ContractCurrency]
[SupplierID]
[ContractDescription]
[ContractType]
[LinkToTemplatefile_DOC]
[SentToSupplier]
[SignBySupplier]
[SignByMercury]
[CollectionBySupplier]
[LinkToPDFcopy]
[ArchivedByMercury]
[UpdatedBy]
[Retention]
[Note]

View 2 Replies

SQL Server :: Update Command Not Writing To Table?

Jan 15, 2011

I have a table that is not getting updated. My insert command is working fine. Here is the update code from business logic area and stored prodecure. The SP works fine when I execute it from sql mgmt studio and updates the table:

[Code]....

View 3 Replies

Databases :: Loop Is Failing When Writing To Table?

Nov 16, 2010

My site extracts data from a MS SQL db and then connects to a mySql db which it writes the data to. My site is working properly when connecting to a db in cPanel at a remote website.

However, I have a mysql db also hosted on my site, and I'm connecting to it ok, but the loop is failing. There are 2 tables, one stores the category, and the other stores link data.

For each category

write to the category table
for each link in this category
write to the link table
next
next

The tables are being created, and the very first category is written to the table, but then nothing gets written to the link table.

How can I make this generate an error message? My webhost doesn't know what to do about it and they just want to see an error message.

I tried this once already, and neither of my lines worked:

HttpContext.Current.Response.Write(lnkid & " " & url)

Why doesn't that get written into the source of the page on each iterance of the loop? How do I see the data that isn't being written?

[Code]....

View 2 Replies

DataSource Controls :: Returns False After Writing Row To Table?

Jun 7, 2010

I don't understand how the stored procedure is returning false. It's supposed to continue looping and continue writing rows. Right now it writes the very first row, and then it goes into the If Not AdvanceLinkBanned.Add(banrec) Then and it goes in here, prints the message and exits the sub. Why is it thinking the add returns false? If Not AdvanceLinkBanned.Add(banrec) ? Doesn't this return the id of the new record? Isn't this not zero? Zero would make it false. How can this be false? Isn't it supposed to return the next record created ? Doesn't SELECT SCOPE_IDENTITY() return the value of the record id? How do I test this?

[Code]....

View 2 Replies

DataSource Controls :: Writing Data To A Table Using Sql Command Object?

Feb 23, 2010

Having serious trouble inserting data into my db... i am able to select and display data just not write it to the database..

[Code]....

View 1 Replies

DataSource Controls :: Update Table Based On Another Table?

Mar 1, 2010

I'm trying to update one my my tables from a field in another table.

I have Address fields on both tables and the old table has some addresses I need to copy over (I dont want to copy/paste or type them all in obviously). I basically need to:

[code]...

View 2 Replies

C# - Adding Another Table Where UserID Can Have A Relationship With Another UserID?

Mar 31, 2011

I have a confusing question, I have a user table and it stores all the usual data for a user that you would expect but im trying to figure out how a user could add another user?

Sounds strange but each user in the User table has his own UI which is UserID how could I add another table where UserID can have a relationship with another UserID?

i.e how would I right the syntax for the above question if I wanted to display all the UserIDs friends on a page. How would I add a friend.

View 4 Replies

MVC :: Display Records From Table 2 Based On Table 1

Aug 7, 2010

I have two tables and I want to display the second one based on the primary key:

the first table is tbl1 (id,fName,lName), and the second one is scnds(id,course,tbl1id).

I am practice using MVC 2.0, so I bulilt the the class repository

[Code]....

Then created the Studentcontroller

[Code]....

The problem is if I used Details method it will show only the first record, but I want to display every course that specific a student has. I don't know if the problem in repository or in the controller.

View 2 Replies

ADO.NET :: Select Corresponding Row In A Table Based On Selection In A Different Table

Jan 25, 2011

I have 3 tables (ShoppingCart, Data, Temporary) in database (Entities) I have no problems in getting data into ShoppingCart. I also know how to transfer data from columns in table ShoppingCart into columns of table Temporary (like EngName, CartID, Date, Quantity etc. - see code below) But I do not know how to multiply Quantity in table ShoppingCart by Price stored in table Data and save it into table Temporary. I think the problem is that I do not know, how to select coressponding row in table Data (see "var myCart2" in my code below) which holds the Price value for EngName previously selected by ("var myCart" also visible in the code). protected void Submit(object sender, EventArgse)

{
using (Entities
db = new Entities())
{
try
{
String
cartId = GetShoppingCartId();
var myCart = (from
cc in db.ShoppingCart
where cc.CartID ==
cartId select
cc);
foreach (ShoppingCart
item in
myCart)
{
int
i = 0;
if
(i < 1)
{
string
engname = item.EngName;
var myCart2 = (from
c in db.Data
where c.EngName ==
engname select
c);
Temporary ta =
new
Temporary();
Data d =
new
Data();

View 1 Replies

Can Insert Rows To Table A Based On Values In Table B By A Single INSERT Statement

Dec 7, 2010

I am doing a data warehouse project.I have two tables tblA (id, type) and tblB(city, no_crimes, type).I want to create (insert) a number of rows based on the value of no_crimes.For Example, in tblB(Leeds, 2000, murder). SO, I need to insert 2000 rows into tblA by a single INSERT statement (not 2000 statements).

View 3 Replies

SQL Server :: Get Data From Table Based On Four?

Aug 21, 2010

I need to know how to show top 30 records from four table with fastest speed.. in ms sql server 2005.

View 3 Replies

Dynamic AJAX Based Data Table?

May 28, 2010

How can I design an efficient AJAX based dynamic table using .NET ? Do I necessarily need to use JQuery / Prototype libraries or plug-ins to achieve this?I am referring to similar implementation : www.coupontom.com

I believe this is not possible using the existing AJAX control toolkit.

View 3 Replies

C# - How To Hide A Column In The Table Based On A Boolean Variable

Jan 13, 2011

So I have an <asp:Gridview> and in my C# file, I am setting the datasource to some database table, and doing .DataBind().

However, I want to hide a column in the table based on a Boolean variable.

Something like this:

gridview.Columns['Field5'].Visible = false;

Or perhaps:

int c = gridview.Rows.Count();
for(int i = 0; i < c; i++){
gridview.Rows['Field5'].Remove();
}

Perhaps I cannot make it invisible, but I'm sure I can at least loop through and remove all rows related to the column "field5". I don't know how to go about doing this.

Does anyone perhaps have a proper link to using the GridView Class and how all the methods are suppose to be used because it's not clear, perhaps not written by microsoft?

the internet seems to lack a lot of C# documentation (or maybe it's just cluttered with too much useless ASP.net information).

View 3 Replies

C# - Adding Rows To A Table Based On User Input?

Jan 19, 2010

I have a TextBox entry field where the user will enter a integer value. And then there is a "Create" button, which when clicked upon must generate a Table with 2 columns :

"Name" and "Email" being the column headers.

I want each row to have a textbox in each of these columns.

All of this has to happen after the button is clicked. I have discovered that if you dynamically add a control in ASP.NET(I am using C#) then the controls are lost during postback. And I don't know how to prevent that from happening.

Can somebody give me some ideas regarding how to go about adding rows dynamically to a table (I tried using the asp.net Server side table control but ran into the "lost-during-postback" problem - can I try with something else like a gridview ? but afaik a GV will not work without data bound to it )

Point to note is that my table has textboxes for user entry and it is not for showing data ..rather it is for accepting data from the user which will be later used to persist details to the database.

View 1 Replies

C# - How To Set A Table Row Color In Repeater Based On The Values Databound

Jun 25, 2010

I have a repeater control:

[code]....

There are more columns in that grid, but I've slimmed it down just for the question.

Now, what I would like to do is change the tr's background color based on the price amount. If it is within different levels, I would like to change the rows background color correspondingly.

Do I have to do this with javascript or is there some way I can get access to the table rows in the code-behind to set this color?

View 3 Replies

SQL Server :: How To Get The Data In A Table Based On Month And Year

Jan 8, 2011

I have a requirement that I have to retrieve data base on month and year.I am using the below query

<pre lang="sql">SELECT SUM(areasft),DATEPART(year, sdate),DATEPART(month, sdate) FROM storedata
GROUP BY DATEPART(year, sdate) ,DATEPART(month, sdate)
ORDER BY DATEPART(year, sDate) ,DATEPART(month, sDate)</pre>

The above query is retrieve data like below.

SUM YEAR MONTH
51013 2000
1
30970 2007
1
NULL 2007
3
900 2007
6
807 2007
8
NULL 2007
9
1756 2007
10
7535 2007
11
NULL 2008
1
1193 2008
2
4230 2008
3
350 2008
4
2200 2008
5
4660 2008
6
6685 2008
8

But I need to display including all the months of the year along with year irrespective of SUM . My query only displays only some months in a year.

View 12 Replies

DataSource Controls :: How To Merge Two Table Based On SQL Query

Jun 7, 2010

This is my table stucture...

This is first table...

ItemNo refno Process Name Qty
001 1 A John 50
001 2 A Jon 150
002 3 B
Kalis 100
003 4 A
Bob 300
Second Table
ItemNo Newrefno Process Name Qty
001 001 ZZ peter 50
001 001/a ZkZ Joe 70
002 002 Ab Ray 100
Result Set
001 A John 200 001/a ZZ ZkZ peter joe 50 70
002 B
Kalis 100 002 Ab Null Ray Null 100 Null
003 A
Bob 300 null null null null null null null

Here first row of the result set explanation:

up to this 001 A John 200 based on first table sum...

and 001/a zz ZkZ peter joe 50 70

here 001/a newrefno of 001 so i need to show all the ItemNo 001 record in one row like the above resultset.

View 4 Replies

Select Query In LINQ Based On Foreign Table

Mar 2, 2011

I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file. OrderDetailsID is a foreign key in Requests Table. I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId. And If there is a row in Requests Table for each OrderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum. Here is the way I implement that. I am looking to prevent using "For each".

iRefund = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1.UnitCost).Sum
Dim objOrderDetails = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1)
For Each OrderDetail As ORM.Entities.OrderDetail In objOrderDetails
If Not OrderDetail.Requests Is Nothing Then
IF OrderDetail.Requests.Last.RequestType="Refund" Then
iRefund -= OrderDetail.UnitCost
End If
End If
Next

View 1 Replies

C# - Set A Table Backcolor Dynamically Based On The Server In The SQL Connectionstring?

Feb 1, 2011

<table style="width: 100%; background-color: #B5C7DE">

i have this table and want to change the background-color to be yellow if the server used int he SQL connection string is not 'pheddv20'i am adding c# code to the page load event to check for this and run the dynamic logic. the connection string is held in the web.config as is typically seen...whats the code look like for this type of action?

View 2 Replies

C# - Populate A Listview Based On 2 Boolean Table Columns?

Feb 11, 2010

I have a database table containing scripts for plays/dramas. The scripts can be categorized under 'Theatre and Education', 'Plays for Young People' or both (by using bools to determine whether they belong to said categories);

scriptID: int
theatreAndEducation:bit
playsForYoungPeople: bit[code]....

View 2 Replies







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