المشاركات : 536
المواضيع 182
الإنتساب : Mar 2016
السمعة :
19
الشكر: 652
تم شكره 264 مرات في 171 مشاركات
السلام عليكم ورحمة الله
محتاد طريقه اطلع فيها رقم الاي دي بعد عمليه ال INSERT
هذا الكود
كود :
conx = New SQLiteConnection(String.Format("Data Source= C:\LOG\{0}\DB{1}.s3db", strcallbk,test))
cmdx = New SQLiteCommand("INSERT INTO DBQTC (station, UTC) Values (@station,@UTC") With {
.Connection = conx
}
conx.Open()
cmdx.Parameters.AddWithValue("@station", strcallbk)
cmdx.Parameters.AddWithValue("@UTC", timk)
cmdx.ExecuteNonQuery()
conx.Close()
محتاج بعد الانزال يطلع لي رقم الاي دي ID لهذا الادخال
وشكرا بارك الله فيكم
المشاركات : 2,061
المواضيع 49
الإنتساب : Oct 2017
السمعة :
538
الشكر: 10647
تم شكره 5322 مرات في 2095 مشاركات
السلام عليكم اخي الكريم
ان كنت تريد رقم id للادخال الذي ادهلته للتو بعد كود الحفظ
فقط استخدم كود max id مع انقاص رقم واحد
قم بانشاء label وضع له هذا الكود
ولتكن هكذا
كود :
Label1.Text = (MaxID("اسم الجدول").Rows(0)(0)) - 1
اما ان كنت تقصد max id فلا تنقص منه سيأتي بأخر قيمة +1
كود :
Txt_id.Text = (MaxID_("اسم الجدول").Rows(0)(0))
اعمل الخير وأجرك لا تنتظره فالله خير من إليك يرده
البرمجة ليست مجرد كود بل هي منهج تفكير منطقي لحل المشكلات
المشاركات : 813
المواضيع 24
الإنتساب : Oct 2012
السمعة :
228
الشكر: 1145
تم شكره 2171 مرات في 815 مشاركات
15-09-18, 12:38 AM
(آخر تعديل لهذه المشاركة : 15-09-18, 12:40 AM {2} بواسطة عبدالله الدوسري.)
بعد تعديل الكود أصبح كالتالي :
كود :
conx = New SQLiteConnection(String.Format("Data Source= C:\LOG\{0}\DB{1}.s3db", strcallbk,test))
cmdx = New SQLiteCommand("INSERT INTO DBQTC (station, UTC) Values (@station,@UTC") With {
.Connection = conx}
conx.Open()
cmdx.Parameters.AddWithValue("@station", strcallbk)
cmdx.Parameters.AddWithValue("@UTC", timk)
cmdx.ExecuteNonQuery()
'------------------------------------
cmdx.CommandText = "SELECT SCOPE_IDENTITY()"
Dim NewID As Integer
NewID = cmdx.ExecuteScalar()
'------------------------------------
conx.Close()
الآن المتغير NewID سيحمل قيمة رقم الـ ID الجديد
الإستعلام : SELECT SCOPE_IDENTITY
يقوم بإرجاع آخر رقم ID تم إنشائة
كما يمكنك إستخدام : SELECT @@IDENTITY
هذا هو الفرق بين SCOPE_IDENTITY وبين IDENTITY@@
SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.
المشاركات : 536
المواضيع 182
الإنتساب : Mar 2016
السمعة :
19
الشكر: 652
تم شكره 264 مرات في 171 مشاركات
15-09-18, 12:46 AM
(آخر تعديل لهذه المشاركة : 15-09-18, 12:49 AM {2} بواسطة dubai.eig.)
(15-09-18, 12:19 AM)ابراهيم ايبو كتب : السلام عليكم اخي الكريم
ان كنت تريد رقم id للادخال الذي ادهلته للتو بعد كود الحفظ
فقط استخدم كود max id مع انقاص رقم واحد
قم بانشاء label وضع له هذا الكود
ولتكن هكذا
كود :
Label1.Text = (MaxID("اسم الجدول").Rows(0)(0)) - 1
اما ان كنت تقصد max id فلا تنقص منه سيأتي بأخر قيمة +1
كود :
Txt_id.Text = (MaxID_("اسم الجدول").Rows(0)(0))
تسلم عزيزي على الرد
بس ما اللي اقصده يختلف عن اللي كتبته عزيزي
بارك الله فيك
(15-09-18, 12:38 AM)عبدالله الدوسري كتب : بعد تعديل الكود أصبح كالتالي :
كود :
conx = New SQLiteConnection(String.Format("Data Source= C:\LOG\{0}\DB{1}.s3db", strcallbk,test))
cmdx = New SQLiteCommand("INSERT INTO DBQTC (station, UTC) Values (@station,@UTC") With {
.Connection = conx}
conx.Open()
cmdx.Parameters.AddWithValue("@station", strcallbk)
cmdx.Parameters.AddWithValue("@UTC", timk)
cmdx.ExecuteNonQuery()
'------------------------------------
cmdx.CommandText = "SELECT SCOPE_IDENTITY()"
Dim NewID As Integer
NewID = cmdx.ExecuteScalar()
'------------------------------------
conx.Close()
الآن المتغير NewID سيحمل قيمة رقم الـ ID الجديد
الإستعلام : SELECT SCOPE_IDENTITY
يقوم بإرجاع آخر رقم ID تم إنشائة
كما يمكنك إستخدام : SELECT @@IDENTITY
هذا هو الفرق بين SCOPE_IDENTITY وبين IDENTITY@@
SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.
تسلم على الرد بارك الله فيك
طلع لي مسج غلط
المشاركات : 653
المواضيع 83
الإنتساب : Sep 2012
السمعة :
81
الشكر: 1558
تم شكره 3397 مرات في 508 مشاركات
SELECT ID FROM TABLE_NAME ORDER BY ID DESC LIMIT 1
المشاركات : 813
المواضيع 24
الإنتساب : Oct 2012
السمعة :
228
الشكر: 1145
تم شكره 2171 مرات في 815 مشاركات
(15-09-18, 12:46 AM)dubai.eig كتب : تسلم على الرد بارك الله فيك
طلع لي مسج غلط
أعتذر لأنني أعتقدت أنها SQL
على العموم إستخدم هذة بدلاً عنها :
SELECT last_insert_rowid()
المشاركات : 536
المواضيع 182
الإنتساب : Mar 2016
السمعة :
19
الشكر: 652
تم شكره 264 مرات في 171 مشاركات
15-09-18, 01:35 AM
(آخر تعديل لهذه المشاركة : 15-09-18, 01:36 AM {2} بواسطة dubai.eig.)
(15-09-18, 01:24 AM)عبدالله الدوسري كتب : (15-09-18, 12:46 AM)dubai.eig كتب : تسلم على الرد بارك الله فيك
طلع لي مسج غلط
أعتذر لأنني أعتقدت أنها SQL
على العموم إستخدم هذة بدلاً عنها :
SELECT last_insert_rowid()
نعم ضبط معاي شكرا لك بارك الله فيك
الحمدالله تسلم على وقتك
(15-09-18, 12:58 AM)أبوبكر سويدان كتب : SELECT ID FROM TABLE_NAME ORDER BY ID DESC LIMIT 1
شكرا استاذي ابوبكر الحمدالله حصلت الجل في رد استاذي عبدالله شكرا لك
المشاركات : 3,815
المواضيع 36
الإنتساب : Mar 2014
السمعة :
724
الشكر: 7238
تم شكره 6709 مرات في 3265 مشاركات
وعليكم السلام ورحمة الله وبركاته
مشاء الله الاخوة لم تقصر بالحل
وليس هذا فقط بال تواجد كلاً من
[*] عبدالله الدوسري
[*] أبوبكر سويدان
عودة حميدة يارب
حتى الاخ ابراهيم ايبو اتى بالرد المناسب ايضاً
لكن يبدو انه لم تصل فكرته لك فكل الشكر والتقدير للمساعدة فى الرد
واتمنى ان تكون دائماً وان لا يتوقف بما يعلمه للغير حتى تعم العلم والائدة للجميع
فكل الشكر والتقدير للجميع
تحياتى لكم
وتمنياتى لكم التوفيق الدائم
|