تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] استفسار :- بخصوص تغيير اسم ال Button بعد الضغط
#9
الحمدالله كل ضبط تمام

بس واجهتني مشكله 

عندما اضغط Add  
لاول مربع يضيف المعلومات ويطلع لي رقم ال id   ---  رقم الاي دي احتاج له في عمليه التحديث 



   

اما في المربع الثاني او الثالث ما يضيف لي المعلومات في القاعده

   

هذا الكود كامل

يمكن في خلل في الكود  ما عرفت اضبطه

كود :
    Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       conx = New SQLiteConnection(String.Format("Data Source= C:\LOG\{0}\DB{1}.s3db", strca, Opencon))

       cmdx = New SQLiteCommand("INSERT INTO DBQTC (d1, d2, d3) Values (@d1,@d2,@d3)") With {
           .Connection = conx
       }

   End Sub


Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
       sender.EndEdit()
       If e.ColumnIndex = 3 Then
           Dim btn As DataGridViewButtonCell = sender.Item(e.ColumnIndex, e.RowIndex)
           If btn.FormattedValue = "Add" Then
               Add(sender.CurrentRow)
               'btn.Style.NullValue = "Update"
           Else
               UpdateX1(sender.CurrentRow)
               'btn.Style.NullValue = "Add"
           End If
       End If

   End Sub

   Private Sub Add(row As DataGridViewRow)

   

       row.Cells(3).Style.NullValue = "Update"
       Dim txt1 As String = TryCast(row.Cells(0).Value, String)
       Dim txt2 As String = TryCast(row.Cells(1).Value, String)
       Dim txt3 As String = TryCast(row.Cells(2).Value, String)

       conx.Open()
 cmdx.Parameters.AddWithValue("@d1", txt1)
       cmdx.Parameters.AddWithValue("@d2", txt2)

       cmdx.Parameters.AddWithValue("@d3", txt3)

     
       '------------------------------------
       cmdx.CommandText = "SELECT last_insert_rowid()"

       NewID = cmdx.ExecuteScalar()
 
       MsgBox(NewID)
   

       MsgBox("Add Row: " & row.Index & vbNewLine &
         "txt1: " & txt1 & vbNewLine &
         "txt2: " & txt2 & vbNewLine &
         "txt3: " & txt3)

       conx.Close()

   End Sub

   Private Sub UpdateX1(row As DataGridViewRow)
       row.Cells(3).Style.NullValue = "Add"
       Dim txt1 As String = TryCast(row.Cells(0).Value, String)
       Dim txt2 As String = TryCast(row.Cells(1).Value, String)
       Dim txt3 As String = TryCast(row.Cells(2).Value, String)


           Dim UPDATPONT As New SQLiteConnection(String.Format("Data Source= C:\LOG\{0}\DB{1}.s3db", strca, Opencon))


           Dim cmdlidXX As New SQLiteCommand("UPDATE DBQTC SET d1=@d1,d2=@d2, d3=@d3 WHERE id=@id ", UPDATPONT)
           UPDATPONT.Open()
           cmdx.Parameters.AddWithValue("@d1",txt1)
           cmdx.Parameters.AddWithValue("@d2", txt1)

           cmdx.Parameters.AddWithValue("@d3", txt1)

           cmdlidXX.Parameters.AddWithValue("@id", NewID)

     

           cmdlidXX.ExecuteNonQuery()


       MsgBox("Update Row: " & row.Index & vbNewLine &
         "txt1: " & txt1 & vbNewLine &
         "txt2: " & txt2 & vbNewLine &
         "txt3: " & txt3)
       MsgBox(NewID)

   End Sub


بارك الله فيكم
الرد }}}
تم الشكر بواسطة: elgokr


الردود في هذا الموضوع
RE: استفسار :- بخصوص تغيير اسم ال Button بعد الضغط - بواسطة dubai.eig - 16-09-18, 08:23 PM


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


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