المشاركات : 769
المواضيع 133
الإنتساب : Feb 2018
السمعة :
64
الشكر: 1636
تم شكره 1073 مرات في 528 مشاركات
السلام عليكم...
اريد دالة وكود الاتصال بالsql من نفس مجلد البرنامج اتصال غير مباشر
مع اكواد الاضافة.والتعديل والحذف.شكرا
المبرمج لا يفكر في المشكلة بل في الحل!!
المشاركات : 2,329
المواضيع 81
الإنتساب : May 2018
السمعة :
522
الشكر: 14039
تم شكره 5671 مرات في 2269 مشاركات
تفضل :
PHP كود :
'------------------------Select With DataSet Vb Code---------------------------' Dim StrSQL as string = "Select * From TableName" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim ds As New DataSet da.Fill(ds,"TableName") If cn.State = ConnectionState.Open Then cn.Close() '------------------------Select With DataTable Vb Code---------------------------' Dim StrSQL as string = "Select * From TableName" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim dt As New DataTable da.Fill(dt) If cn.State = ConnectionState.Open Then cn.Close() '------------------------INSERT With DataTable Vb Code---------------------------' Dim StrSQL as string = "INSERT INTO Castomer (ID,Castomer_Name,Castomer_Tel,Castomer_Mobaile,Castomer_Note ) VALUES ('" & Txt_ID.Text & "','" & Txt_Castomer_Name.Text & "','" & Txt_Castomer_Tel.Text & "','" & Txt_Castomer_Mobaile.Text & "','" & Txt_Castomer_Note.Text & "')" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim dt As New DataTable da.Fill(dt) If cn.State = ConnectionState.Open Then cn.Close() '------------------------Update With DataTable Vb Code---------------------------' Dim StrSQL as string = "UPDATE Castomer SET Castomer_Name='" & Txt_Castomer_Name.Text & "', Castomer_Tel='" & Txt_Castomer_Tel.Text & "', Castomer_Mobaile='" & Txt_Castomer_Mobaile.Text & "', Castomer_Note='" & Txt_Castomer_Note.Text & "' Where ID='" & Txt_ID.Text & "'" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim dt As New DataTable da.Fill(dt) If cn.State = ConnectionState.Open Then cn.Close() '------------------------Delete With DataTable Vb Code---------------------------' Dim StrSQL as string = "Delete From Castomer Where ID = '"& Txt_ID.Text & "'" Dim TxtID As String =Txt_ID.Text If MsgBox("هل أنت متأكد من حذف السجل المحدد " & Txt_ID.Text, MsgBoxStyle.YesNo + MsgBoxStyle.Question + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading, "حذف سجل") = MsgBoxResult.Yes Then Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim dt As New DataTable da.Fill(dt) If cn.State = ConnectionState.Open Then cn.Close() MsgBox("تم حذف السجل المحدد "& Txt_ID.Text &" بنجاح ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading, "حذف سجل") End If
سبحان الله وبحمده سبحان الله العظيم و الحمد لله ولا اله الا الله والله اكبر
المشاركات : 769
المواضيع 133
الإنتساب : Feb 2018
السمعة :
64
الشكر: 1636
تم شكره 1073 مرات في 528 مشاركات
(26-03-19, 12:12 PM)asemshahen5 كتب : تفضل :
PHP كود :
'------------------------Select With DataSet Vb Code---------------------------' Dim StrSQL as string = "Select * From TableName" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim ds As New DataSet da.Fill(ds,"TableName") If cn.State = ConnectionState.Open Then cn.Close() '------------------------Select With DataTable Vb Code---------------------------' Dim StrSQL as string = "Select * From TableName" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim dt As New DataTable da.Fill(dt) If cn.State = ConnectionState.Open Then cn.Close() '------------------------INSERT With DataTable Vb Code---------------------------' Dim StrSQL as string = "INSERT INTO Castomer (ID,Castomer_Name,Castomer_Tel,Castomer_Mobaile,Castomer_Note ) VALUES ('" & Txt_ID.Text & "','" & Txt_Castomer_Name.Text & "','" & Txt_Castomer_Tel.Text & "','" & Txt_Castomer_Mobaile.Text & "','" & Txt_Castomer_Note.Text & "')" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim dt As New DataTable da.Fill(dt) If cn.State = ConnectionState.Open Then cn.Close() '------------------------Update With DataTable Vb Code---------------------------' Dim StrSQL as string = "UPDATE Castomer SET Castomer_Name='" & Txt_Castomer_Name.Text & "', Castomer_Tel='" & Txt_Castomer_Tel.Text & "', Castomer_Mobaile='" & Txt_Castomer_Mobaile.Text & "', Castomer_Note='" & Txt_Castomer_Note.Text & "' Where ID='" & Txt_ID.Text & "'" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim dt As New DataTable da.Fill(dt) If cn.State = ConnectionState.Open Then cn.Close() '------------------------Delete With DataTable Vb Code---------------------------' Dim StrSQL as string = "Delete From Castomer Where ID = '"& Txt_ID.Text & "'" Dim TxtID As String =Txt_ID.Text If MsgBox("هل أنت متأكد من حذف السجل المحدد " & Txt_ID.Text, MsgBoxStyle.YesNo + MsgBoxStyle.Question + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading, "حذف سجل") = MsgBoxResult.Yes Then Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim dt As New DataTable da.Fill(dt) If cn.State = ConnectionState.Open Then cn.Close() MsgBox("تم حذف السجل المحدد "& Txt_ID.Text &" بنجاح ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading, "حذف سجل") End If
اولا اشكرك جدا وسؤال هل ينفع استخدم اكواد الاكسس
في البحث او الاستعلام ام ماذا شكرا.
المبرمج لا يفكر في المشكلة بل في الحل!!
المشاركات : 2,329
المواضيع 81
الإنتساب : May 2018
السمعة :
522
الشكر: 14039
تم شكره 5671 مرات في 2269 مشاركات
ماذا تعني بأكواد أكسيس .
سبحان الله وبحمده سبحان الله العظيم و الحمد لله ولا اله الا الله والله اكبر
المشاركات : 769
المواضيع 133
الإنتساب : Feb 2018
السمعة :
64
الشكر: 1636
تم شكره 1073 مرات في 528 مشاركات
(26-03-19, 01:59 PM)asemshahen5 كتب : ماذا تعني بأكواد أكسيس .
-اعني اخي الاكواد المستخدمة مثل البحث وكود الاقتراح في الاكسس
المبرمج لا يفكر في المشكلة بل في الحل!!
المشاركات : 2,329
المواضيع 81
الإنتساب : May 2018
السمعة :
522
الشكر: 14039
تم شكره 5671 مرات في 2269 مشاركات
26-03-19, 03:12 PM
(آخر تعديل لهذه المشاركة : 26-03-19, 03:12 PM {2} بواسطة asemshahen5.)
ضع كود مبسط عما تعني إذا كنت تقصد استعلام البحث نفس الاستعلام
PHP كود :
Dim StrSQL as string = "Select * From TableName Where ColomnName='" & Txt_ColumnName.Text & "'" Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;") If cn.State = ConnectionState.Closed Then cn.Open() Dim da As New SqlDataAdapter(StrSQL, cn) Dim ds As New DataSet da.Fill(ds,"TableName") If cn.State = ConnectionState.Open Then cn.Close() Txt_FullName.Text=Dt.rows(0)("FullName").ToString
سبحان الله وبحمده سبحان الله العظيم و الحمد لله ولا اله الا الله والله اكبر
|