تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
مشكلة في كود الحذف مع استخدام Sql 2008
#1
  السلام عليكم الاخوة الاعزاء

برجاء المساعدة في كود الحذف في هذا المشروع


انا استخدم Sql server 2008 R2

مع الشكر



Imports

System.Data.SqlClientPublic

Class ERC_2G

' جملة الربط

Public connSQLServer As New SqlConnection("Data Source= DELL-PC\omar;Initial Catalog= Ericsson;Integrated Security=True")

Dim da As SqlDataAdapter

Dim dt As New DataTable
 


Sub Load_Data()
dt.Clear()


' تغير اسم الجدول هنا اسمه table1da =

New SqlDataAdapter("Select * From ERC_2G", connSQLServer)
da.Fill(dt)


End Sub

Sub save_Data()

Dim save As New SqlCommandBuilder(da)save.QuotePrefix =

"["save.QuoteSuffix =

"]"
da.Update(dt)

dt.AcceptChanges()


End Sub



Public Function Max_ID_From_dt()

Dim Number As Integer

Try

Dim cmd As New SqlDataAdapter("Select Max(ID) From dt", connSQLServer)
connSQLServer.Open()


' Number = cmd.ExecuteScalar
connSQLServer.Close()


Catch
Number = 0

connSQLServer.Close()


End Try

Return Number

End Function



' Clear Function

Private Sub clear()
TextIDText.Clear()

Site_RegionText.Clear()

Site_KeyText.Clear()

Node_NameText.Clear()

SystemText.Clear()

TechnologyText.Clear()

Cabinet_TypeText.Clear()

Site_ActivityText.Clear()

ConfigurationText.Clear()

StatusText.Clear()

DateTimePicker1.Value = Now

LAC_TACText.Clear()

ParentsText.Clear()

PriorityText.Clear()

PhaseText.Clear()

FON_IDText.Clear()

BH_TypeText.Clear()


End Sub

'================================================================================================================================================================

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Load_Data()

DataGridView1.DataSource = dt


End Sub
 


' كود مفتاح الحذف

Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click



If TextIDText.Text = "" ThenMsgBox(

"لم يتم اختيار سجل لحذفه")

Exit Sub

End If

Dim bc As Integer = BindingContext(dt).Position

Dim pos As Integer = DataGridView1.CurrentRow.Index

Dim posNm = DataGridView1.Rows(pos).Cells("Site_Region").Value

Dim posID = DataGridView1.Rows(pos).Cells("ID").Value
 


If MsgBox("هل تريد الحذف فعلاً " & posNm, MsgBoxStyle.Question + vbYesNo, Title:="تحذير") = vbYes Then

Dim cmd As New SqlDataAdapter("DELETE FROM ERC_2G WHERE ID =" & TextIDText.Text, connSQLServer)
connSQLServer.Open()

connSQLServer.Close()

dt.Clear()

Load_Data()

BindingContext(dt).Position = pos
MsgBox(

"تم الحذف")

Else

Return

End If
save_Data()

Load_Data()

clear()


End Sub
 
End

Class















































الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
مشكلة في كود الحذف مع استخدام Sql 2008 - بواسطة khaled12345 - 12-11-17, 04:24 AM


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


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