تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
ما هو حل مشكلة هذا ال Error The connection was not closed. The connection's current
#1
كود :
Dim dt1 As New DataTable
       Dim cmd As New SqlCommand("select * from Products where ProductBarcode = '" + ProductBarcode.Text + "'", con)
       con.Open()
       Dim da As New SqlDataAdapter(cmd)
       da.Fill(dt1)
       If dt1.Rows.Count > 0 Then

           Dim A As Integer = Val(Qyt.Text)
           Dim cmdupdate As New SqlCommand

           With cmdupdate
               .Connection = con
               .CommandType = CommandType.Text
               .CommandText = "update Products set Qyt = Qyt + " & A & " where ProductBarcode = " & ProductBarcode.Text & ""

           End With
           Try
               If con.State = 1 Then con.Close()
               con.Open()
               cmdupdate.ExecuteNonQuery()
               con.Close()
               MsgBox("اسم المادة المدخلة موجود مسبقا - تم عملية التحديث بنجاح", MsgBoxStyle.Information, "تحديث كمية المادة")
               cmdupdate = Nothing
           Catch ex As Exception
               con.Close()
               MsgBox(Err.Description, MsgBoxStyle.Information)
           Finally
               If con.State = ConnectionState.Open Then con.Close()
           End Try
       Else
           insert_products(ProductID.Text, ProductName.Text, ProductBarcode.Text, CatID.Text, UnitID.Text, Qyt.Text, BuyPrice.Text, SellPrice.Text, ImporterID.Text)

       End If
       clearcontroal()
       ProductID.Text = getmaxid("Products", "ProductID")
الرد }}}
تم الشكر بواسطة:
#2
الاتصال مفتوح وانت تحاول تفتح الاتصال مره أخرى .

افتح الاتصال في بداية الكود ونفذ جميع العمليات وفي نهاية الكود اغلق الاتصال .
يا رحمن الدنيا والآخرة ورحيمهما
الرد }}}
تم الشكر بواسطة: princelovelorn
#3
(12-02-19, 07:26 AM)حريف برمجة كتب : الاتصال مفتوح وانت تحاول تفتح الاتصال مره أخرى .

افتح الاتصال في بداية الكود ونفذ جميع العمليات وفي نهاية الكود اغلق الاتصال .

ممكن معلش تقولى اعمل اية فى الكود ؟
الرد }}}
تم الشكر بواسطة:
#4
كود :
      Dim dt1 As New DataTable
      Dim cmd As New SqlCommand("select * from Products where ProductBarcode = '" + ProductBarcode.Text + "'", con)
      '----------------------------------------------------'
       If con.State = ConnectionState.Closed Then con.Open()
       '----------------------------------------------------'
      Dim da As New SqlDataAdapter(cmd)
      da.Fill(dt1)
      If dt1.Rows.Count > 0 Then
          Dim A As Integer = Val(Qyt.Text)
          Dim cmdupdate As New SqlCommand
          With cmdupdate
              .Connection = con
              .CommandType = CommandType.Text
              .CommandText = "update Products set Qyt = Qyt + " & A & " where ProductBarcode = " & ProductBarcode.Text & ""
          End With
          Try
              If con.State = 1 Then con.Close()
              con.Open()
              cmdupdate.ExecuteNonQuery()
              con.Close()
              MsgBox("اسم المادة المدخلة موجود مسبقا - تم عملية التحديث بنجاح", MsgBoxStyle.Information, "تحديث كمية المادة")
              cmdupdate = Nothing
          Catch ex As Exception
              con.Close()
              MsgBox(Err.Description, MsgBoxStyle.Information)
          Finally
              If con.State = ConnectionState.Open Then con.Close()
          End Try
      Else
          insert_products(ProductID.Text, ProductName.Text, ProductBarcode.Text, CatID.Text, UnitID.Text, Qyt.Text, BuyPrice.Text, SellPrice.Text, ImporterID.Text)
      End If
      clearcontroal()
      ProductID.Text = getmaxid("Products", "ProductID")
الرد }}}
تم الشكر بواسطة: princelovelorn , sendbad100 , mostafa nada



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


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم