.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

dataset - delete tables - Cascade

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
I have two table:- tbl_Payments- tbl_PaymentDetailsMy code:DataSet1TableAdapters.tbl_PaymentsTableAdapter cta = new DataSet1TableAdapters.tbl_PaymentsTableAdapter();cta.DeleteQuery();Dataset query:DELETE FROM tbl_PaymentsFROM            tbl_Payments INNER JOIN                         tbl_PaymentDetails ON tbl_Payments.ID = tbl_PaymentDetails.PaymentIdRelation:Key columns (tbl_Payments) | Foreign Key Columns (tbl_PaymentDetails)ID                                          | PaymentIdChoose what to createSelect: Foreign Key Constraint OnlyUpdate Rule: CascadeDelete Rule: CascadeWhy delete only the data from the first table?Data from other tables remain.Please help.LangDetecten>sl GoogleDicCCascade

View Complete Post

More Related Resource Links

merging multiple tables in a single dataset to single table


 i have a stored procedure which returns three tables to a dataset ..... now i need to merge all three tables to a single table from d same dataset 

like dataset1 has table1 table2 and table3 .... i want all the three tabels to be merged into dataset1 itself .... instead of three diffrent tables so that i can show all three table data in a single datagrid  as a compact data and combination of 3 tables from d single dataset.....

can some1 help me please.....

Sql Scripts - Delete all Tables, Procedures, Views and Functions


In a shared environment you typically don't have access to delete your database, and recreate it for fresh installs of your product. 

I managed to find these scripts which should help you clean out your database.

Use at your own risk.


Delete All Tables

--Delete All Keys


insert new records in tables from dataset to database


I have 2 tables in SqlServer 2008.

Table1: T1id, SomeData

Table2: T2id, T1id, SomeData

I am using DataAdapter.FillSchema to create shema of tables in DataSet. I created DataRelation on columns T1id in both tables.

Now when i try to Update Sql Database T1id in Table2 remains 0 and not the value of T1id in Table1.

I can successfully update Sql Database if i fill DataSet with records first (Using DataAdapter.Fill), but that's not what i want to do. I don't need "old" records in my dataset. I want to use dataset just to store all imputs from user until the proccess is done and then insert all those records "at the same time".

I think i'm getting it wrong with ForeignKeyConstraints, maybe UpdateRule is not set to cascade, i just don't know.

I have been trying to work this out for 6 days now and i'm about to break something on half.

Can someone please guide me to right direction, maybe post some sample, anything.... please!

My old post regarding this:

How to update Sql Server related tables from Dataset(SchemaFill)

SqlDataAdapter.Update related tables

How to update Sql Server related tables from Dataset(SchemaFill)

Hi!I would like to update new records that get inserted in DataSet to Sql Server Database.Below is a working example of how to do this if you use "DataAdapter.Fill(ds)". But i don't want to fill data, becouse i don't need data, i only need shema (I will use this dataset to insert new data to Sql), so i would like to use "DataAdapter.FillSchema(ds)"Please help me out at least with this one... i'm stuck... can't continue untill i crack this nut.<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td> <asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="True"> <Columns> <asp:CommandField ShowSelectButton="True" /> </Columns>

delete a row in datatable using linq to dataset

hihow can i delete a row in datatable using linq to dataset?I have a dataset in my project, need to delete some rows filtered by IDhow can i do?

DataAdaptor/Dataset problems when no row present in database tables

Hi All, I'm trying to use a DataSet to maintain some rows for a table, and when I've finished my changes, send all changes to the database using a SqlDataAdapter.    I find if there are no rows in the table in the database then I am getting a 'Object reference not set to an instance of an object' when I try to access the table in the Dataset. Is there a way to work with a Dataset like this ie. I start off with an empty table and I wish to add rows, to access the structure of the table rows, build rows, then add them and do the update on the SQLDataAdapter. Thanks, Sinead Here is my code: protected SqlDataAdapter memberDA = new SqlDataAdapter(); protected DataSet memberDS { get { if (ViewState["memberDS"] != null) return (DataSet)ViewState["memberDS"]; else return new DataSet(); } set { ViewState["memberDS"] = value; } } protected SqlDataAdapter getDataAdapterForMembers() { SqlConnection conn = new SqlConnection(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["SiteDBConn"].ConnectionString; memberDA = new SqlDataAdapter("usp_GetMembers", conn); memberDA.SelectCommand.CommandType = CommandType.Stored

Delete from multiple tables

 After trying myriad ways to accomplish deleting from two table, I found a way that actually works. However, AM am sure there is a better way to do this. Any ideas?  Imports System.Data Imports System.Data.SqlClient Imports Telerik.Web.UI Imports System.CodeDom Imports System.Web Partial Class Default2 Inherits System.Web.UI.Page Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sql As String Dim strConnString As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("CF_SQL_Connection").ConnectionString() sql = "DELETE FROM Table1 WHERE IDTable1 = '5'" Dim connection As New SqlConnection(strConnString) Dim command As New SqlCommand(sql, connection) command.Connection.Open() command.ExecuteNonQuery() command.Connection.Close() Dim sql1 As String Dim strConnString1 As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("CF_SQL_Connection").ConnectionString() sql1 = "DELETE FROM Table2 WHERE IDTable1 = '5'" Dim connection1 As New SqlConnection(strConnString) Dim command1 As New SqlCommand(sql1, connection) command1.Connection.Open() command1.ExecuteNonQuery() command1.Connec

linq - delete two tables not work

BurnbetDataContext db = new BurnbetDataContext(); var q = (from c in db.GetTable<tbl_Payment>() where c.UserId == "fc44c835-8e80-45ee-af84-68339a09c053" select c).Single<tbl_Payment>(); db.GetTable<tbl_Payment>().DeleteOnSubmit(q); db.SubmitChanges(); In App_Code I BurnbetDataContext.I have two tables and tbl_PaymentDetails tbl_PaymentAssociation is:Parent Child Class -->>> UserId UserId ClassData in Table tbl_PaymentDetails (child) does not delete.      

Delete records if it is not getting inserted and also in the related tables

Hi All, If the insert into table person is successful, but the insert into table subject fails, delete the person record and all records associated with the person that were also inserted. If the insert into table person is successful, and the insert into subject is successful, but the insert into the booking table fails, delete the subject record, the person record ,and all records associated with the person that were also inserted. The reason for the failure into the 3 tables (person, subject, booking) should be logged to tblErrors . Also, a message should be written to tblErrors which logs the fact that this situation has occurred.     -- I have few stored procs which does inserts and updates How would i capture the record which is not getting inserted and log in to log table and delete the previous records which got inserted  which are related to that.

how to delete records from multiple tables.


Hi Friends,Tell me How to delete records from multiple tables by using a single query.

Multiple Tables on One Page, One Dataset



In SSRS 2005, is there a way to have 2 tables on a page, each displaying a row of data from the same dataset?

In other words:

Page 1, Table 1 data = row 1

Page 1, Table 2 data = row 2

---- new page ----

Page 2, Table 1 data = row 3

Page 2, Table 2 data = row 4

and so on?

avoid accidental delete on Subscriber tables - transactional replication


Hello pundits..

I am looking to see if we have any way to set on the subcsriber to avoid accidental deletes on subscriber tables to avoid the 20598 error(where the publisher is trying to replicate a record not existing(rather deleted in accident) at the subscriber end). This is for transactional replication


Synchronizing two tables on two databases with a dataset - MS Access



I have a C# problem I need to synchronize two MS Access tables from two different databases(two databases over a network) which is quite similar, I thought of using two different OleDbConnections and two DataAdapters to fill a Single DataSet and then manipulate the data in the DataSet, I think the source table (database with the primary data) should be loaded first (into the DataSet) then the secondary table from the remote database should subtract the existing records in the DataSet to get the difference then the difference should be Appended to the remote table, but I don't know how to remove the same records from the DataSet and to send the remaining records to the secondary database.

Here is some code I already have, but I don't know how to get this to work:

        private void btn_update_Click(object sender, EventArgs e)

        private void UpdateExperiment()
            OleDbConnection connSource = new OleDbConnection();
            OleDbConnection connDest = new OleDbConnection();
            OleDbDataAdapter daSource = new OleDbDataAdapter();
            OleDbDataAdapter daDest = new OleDbDataAdapter();
            OleDbCommand commSource = new OleDbCommand();
            OleDbCommand commDest = new OleDbCommand();
            DataSet ds

Does Linq dbml need refreshed after allowing cascade deletes on tables?


Hi all-

When setting up my database, I forgot to set the delete rule to cascade on foreign keys.  Now, I can't delete a user from the ASP.net control panel due to the FK constraints.  So, I need to go through all my tables and allow cascade delete on all keys.

Once I do this, will I need to redo  my Linq .dbml?  (ie: delete each table on it and drag it back on) or does it not matter?

Can I create multiple report tables from one Dataset?


I'm producing a report in Report Builder 3.0 that needs to show events grouped by time of day, and another table with the same data grouped by day of week. Both tables show the same results, just grouped differently. The query that generates the ungrouped data is expensive, so I don't want to run it twice.

I've created queries in Management Studio that get the ungrouped data into a global temp table, and then I can fetch both grouped data sets from there. Unfortunately I can't get this to work in Report Builder. I have one Dataset that runs the main query, saves it into global temp, and then returns the first result set. The second Dataset returns the results from global temp. This keeps failing, the second result set is blank.

Does Reporting services run the queries in the order they are in the report, or are they run concurrently? If they are run concurrently this would explain it. Is there anything I can do to change this so that the second query doesn't run until the first one has completed?

Is there a better way of achieving the results I'm after?

Get Data from 2 tables into 1 DataSet?



I have 2 tables, one called Products, one called Auctions.

I need to have 1 DataSet that includes all the info of the Auction, and Auction has a column named ProductID 

So i need to get all the info from the Products table where the ProductID on the Auctions table matchs.

And all of that need to be in 1 DataSet so i can print it.

I really have no idea on how to do it...

Can anyone help me?




Dataset.tables.Select method


I want to select student who belogs to New York.so this purpose i write query as

ds.Tables("student").select("city==NewYork"); it is not work


"ds" is dataset

"city" is column name

"New York" is the string

Can anybody help me? 

Give me suggestion 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend