﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Релиб / Программирование / .NET / C#  / База данных(удаление) / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>Релиб</description><link>http://www.relib.com/forums/</link><webMaster>robot@relib.com</webMaster><lastBuildDate>Sat, 22 Nov 2008 12:28:32 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: База данных(удаление)</title><link>http://www.relib.com/forums/Topic902440-26-1.aspx</link><description>Понял как с этим работать - используется RealtionShip.&lt;/P&gt;&lt;P&gt;//создание поделючения&lt;/P&gt;&lt;P&gt;OleDbConnection dc = new OleDbConnection(conn_string);&lt;/P&gt;&lt;P&gt;dc.Open();&lt;/P&gt;&lt;P&gt;OleDbDataAdapter da = new OleDbDataAdapter(&lt;/P&gt;&lt;P&gt;"select id_student, Surname, Name, LastName, type_learn, dateborn, " +&lt;/P&gt;&lt;P&gt;"id_group from List_students", dc);&lt;/P&gt;&lt;P&gt;OleDbDataAdapter da_est = new OleDbDataAdapter(&lt;/P&gt;&lt;P&gt;"select * from List_estimations where (id_student = " + &lt;/P&gt;&lt;P&gt;id.ToString() + ")", dc);&lt;/P&gt;&lt;P&gt;//команды удаления&lt;/P&gt;&lt;P&gt;da.DeleteCommand = new OleDbCommand("delete from List_students where " +&lt;/P&gt;&lt;P&gt;"(id_student = @id_student)", dc);&lt;/P&gt;&lt;P&gt;da.DeleteCommand.Parameters.Add("@id_student", &lt;/P&gt;&lt;P&gt;OleDbType.Integer, 4, "id_student");&lt;/P&gt;&lt;P&gt;da_est.DeleteCommand = new OleDbCommand("delete from List_estimations " + &lt;/P&gt;&lt;P&gt;"where id_estimation = @id_estimation", dc);&lt;/P&gt;&lt;P&gt;da_est.DeleteCommand.Parameters.Add("@id_estimation", &lt;/P&gt;&lt;P&gt;OleDbType.Integer, 4, "id_estimation");&lt;/P&gt;&lt;P&gt;//заполнение данными&lt;/P&gt;&lt;P&gt;DataSet ds = new DataSet("List_students; List_estimations");&lt;/P&gt;&lt;P&gt;da.Fill(ds, "List_students");&lt;/P&gt;&lt;P&gt;da_est.Fill(ds, "List_estimations");&lt;/P&gt;&lt;P&gt;DataRelation rel = new DataRelation("id_student",&lt;/P&gt;&lt;P&gt;ds.Tables["List_students"].Columns["id_student"],&lt;/P&gt;&lt;P&gt;ds.Tables["List_estimations"].Columns["id_student"]);&lt;/P&gt;&lt;P&gt;ds.Relations.Add(rel);&lt;/P&gt;&lt;P&gt;//само удаление&lt;/P&gt;&lt;P&gt;DataRow row = ds.Tables["List_students"].Select("id_student = '" + &lt;/P&gt;&lt;P&gt;id.ToString() + "'")[0];&lt;/P&gt;&lt;P&gt;row.Delete();&lt;/P&gt;&lt;P&gt;da.Update(ds, "List_students");&lt;/P&gt;&lt;P&gt;da_est.Update(ds, "List_estimations");&lt;/P&gt;&lt;P&gt;dc.Close();&lt;/P&gt;</description><pubDate>Thu, 10 Aug 2006 13:29:33 GMT</pubDate><dc:creator>Marsel</dc:creator></item><item><title>База данных(удаление)</title><link>http://www.relib.com/forums/Topic902440-26-1.aspx</link><description>Есть такой пример&lt;/P&gt;&lt;P&gt;В таблице есть несколько строк с одинаковым значением id_student&lt;/P&gt;&lt;P&gt;Нужно удалить все строки со определённым значением id_student&lt;/P&gt;&lt;P&gt;Делаю так&lt;/P&gt;&lt;P&gt;da_est.DeleteCommand = new OleDbCommand("delete from List_estimations " +&lt;/P&gt;&lt;P&gt;"where (id_student = " + id.ToString() + ")", dc);&lt;/P&gt;&lt;P&gt;DataRow[] rows = ds.Tables["List_estimations"].Select("id_student = " +&lt;/P&gt;&lt;P&gt;id.ToString() + "");&lt;/P&gt;&lt;P&gt;rows[0].Delete();&lt;/P&gt;&lt;P&gt;da_est.Update(ds, "List_estimations");&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Я одной командой удаляю несколько строк. Как то коряво получается.&lt;/P&gt;&lt;P&gt;Можно ли это сделать более красиво и правильно ли я вообще делаю?&lt;/P&gt;</description><pubDate>Thu, 10 Aug 2006 10:29:18 GMT</pubDate><dc:creator>Marsel</dc:creator></item></channel></rss>