تقييم الموضوع :
  • 1 أصوات - بمعدل 2
  • 1
  • 2
  • 3
  • 4
  • 5
كيف يمكنني عمل trigger يقوم بإضافة بيانات حقل من جدول ما إلى حقل في جدول آخر
#15
أخي محمد فعلا خطرت ببالي هذه الفكرة من قبل وقمت بتجربتها إلا أنه لايقوم بتخزين قيمة حقل الشعبة بداخل جدول الشعبsections
فيما يلي الكود الذي استخدمته والملف المرفق

كود :
[SIZE=2]
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/color][/SIZE][/COLOR][/SIZE][SIZE=2] connstr [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]As[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]String[/color][/SIZE][/COLOR][/SIZE][SIZE=2] = ConfigurationManager.ConnectionStrings([/SIZE][SIZE=2][color=#a31515][SIZE=2][COLOR=#a31515]"ConnectionString"[/color][/SIZE][/COLOR][/SIZE][SIZE=2]).ConnectionString[/SIZE]

[SIZE=2]
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Protected[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/color][/SIZE][/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/color][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]As[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Object[/color][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/color][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]As[/color][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/color][/SIZE][/COLOR][/SIZE][SIZE=2] Button1.Click[/SIZE]
[SIZE=2]        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/color][/SIZE][/COLOR][/SIZE][SIZE=2] cn [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]As[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]New[/color][/SIZE][/COLOR][/SIZE][SIZE=2] SqlConnection(connstr)[/SIZE]
[SIZE=2]        cn.Open()
        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/color][/SIZE][/COLOR][/SIZE][SIZE=2] cname [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]As[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]String[/color][/SIZE][/COLOR][/SIZE][SIZE=2] = t1.Text[/SIZE]
[SIZE=2]        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/color][/SIZE][/COLOR][/SIZE][SIZE=2] secname [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]As[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]String[/color][/SIZE][/COLOR][/SIZE][SIZE=2] = t2.Text[/SIZE]
[SIZE=2]        
        
[/SIZE][SIZE=2][color=#008000][SIZE=2][COLOR=#008000]'-----------------------------------------------------------[/color][/SIZE][/COLOR][/SIZE]
[SIZE=2]        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/color][/SIZE][/COLOR][/SIZE][SIZE=2] myTrans = cn.BeginTransaction()[/SIZE]
[SIZE=2]        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/color][/SIZE][/COLOR][/SIZE][SIZE=2] myCommand [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]As[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]New[/color][/SIZE][/COLOR][/SIZE][SIZE=2] SqlCommand()[/SIZE]
[SIZE=2]        myCommand.Connection = cn
        myCommand.Transaction = myTrans
    
        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Try[/color][/SIZE][/COLOR][/SIZE]
[SIZE=2]            myCommand.CommandText =
[/SIZE][SIZE=2][color=#a31515][SIZE=2][COLOR=#a31515]"insert into t1 (classname) values( '"[/color][/SIZE][/COLOR][/SIZE][SIZE=2] + cname + [/SIZE][SIZE=2][color=#a31515][SIZE=2][COLOR=#a31515]"')"[/color][/SIZE][/COLOR][/SIZE]
[SIZE=2]            myCommand.ExecuteNonQuery()
            myCommand.CommandText = (
[/SIZE][SIZE=2][color=#a31515][SIZE=2][COLOR=#a31515]"INSERT INTO sections (classno) select top(1) classno from t1 order by classno desc "[/color][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]            myCommand.ExecuteNonQuery()
            myCommand.CommandText = (
[/SIZE][SIZE=2][color=#a31515][SIZE=2][COLOR=#a31515]"update sections set section =('"[/color][/SIZE][/COLOR][/SIZE][SIZE=2] + secname + [/SIZE][SIZE=2][color=#a31515][SIZE=2][COLOR=#a31515]"')where secid =(Select max(secid) from sections"[/color][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]            myTrans.Commit()
            Response.Write(
[/SIZE][SIZE=2][color=#a31515][SIZE=2][COLOR=#a31515]"Both records are written to database."[/color][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Catch[/color][/SIZE][/COLOR][/SIZE][SIZE=2] ep [/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]As[/color][/SIZE][/COLOR][/SIZE][SIZE=2] Exception[/SIZE]
[SIZE=2]            myTrans.Rollback()
            Response.Write(
[/SIZE][SIZE=2][color=#a31515][SIZE=2][COLOR=#a31515]"Neither record was written to database."[/color][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Finally[/color][/SIZE][/COLOR][/SIZE]
[SIZE=2]            cn.Close()
        
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]End[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Try[/color][/SIZE][/COLOR][/SIZE]
[SIZE=2]    
    
[/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]End[/color][/SIZE][/COLOR][/SIZE][SIZE=2][color=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/color][/SIZE][/COLOR][/SIZE]


الملفات المرفقة
.zip   wsreg2.zip (الحجم : 236.16 ك ب / التحميلات : 37)
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
كيف يمكنني عمل trigger يقوم بإضافة بيانات حقل من جدول ما إلى حقل في جدول آخر - بواسطة dena - 04-07-13, 02:16 PM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [مقال] كيفية برمجة منتدى TextForum بدون قاعدة بيانات سعود 55 11,371 15-02-25, 08:31 PM
آخر رد: سعود
  كيفية عمل صفحة ويب وربطها بتقعدة بيانات علي جهاز makky 1 1,925 06-01-22, 11:48 AM
آخر رد: ahmedabdelaliem
  كيف اضيف بيانات الى gridview بدون استخدام datasource ؟؟ nowiglah 1 2,741 06-12-20, 08:36 PM
آخر رد: Osama_NY
  كيفية عرض بيانات اعضاء هيئية تدريس مع الصورة cordava 0 1,579 19-09-20, 07:03 PM
آخر رد: cordava
  [سؤال] خطأ عند انشاء قاعدة بيانات من داخل فجول استوديو2013 alsihran 1 2,475 30-03-20, 06:07 PM
آخر رد: alsihran
  كيف اسوي فورم ادخال بيانات الحكيمي 0 2,236 13-03-17, 11:01 AM
آخر رد: الحكيمي
  [C#.NET] مشكلة في حفظ بيانات cascading dmw2200 0 2,084 14-11-16, 02:08 PM
آخر رد: dmw2200
  كيف يتم بحت من خلال taxtbox وتضهر بيانات في داتا قريد فيو habib 2 2,945 29-10-16, 05:20 PM
آخر رد: أبو عمر
Exclamation كيف اسوي صفحة إدخال بيانات في ASP.NET ؟ أبو عمر 8 4,729 12-09-16, 11:32 PM
آخر رد: Abu Ehab
  أريد تصميم برنامج قواعد بيانات عبر الانترنت salim1281 3 3,176 24-11-15, 12:50 PM
آخر رد: HASAN6.0

التنقل السريع :


يقوم بقرائة الموضوع: