تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] Object reference not set to an instance of an object.
#1
السلام عليكم ورخمة الله وبركاته

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

كود :
If Ds.Tables("SpecialColor").AsEnumerable().Count(Function(row) row.Field(Of String)("Ref").ToLower() = Trim(RefTxt.Text.ToLower())) > 0 Then
            MsgBox("Order added Before !", MsgBoxStyle.Information)
            Return
        End If

كود بالكامل

كود :
Imports System.Data.OleDb
Public Class SpecialColor
    Dim Con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=|DataDirectory|\db1.mdb;")

    Dim Sqltr As String = "Select * From SpecialColor Where OrderNo LIKE '%" & addOrder.OrderNoText.Text & "%'"
    Dim Da As New OleDbDataAdapter(Sqltr, Con)
    Dim Ds As New DataSet
    Dim Cmdb As New OleDbCommandBuilder

    Private Sub SpecialColor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Da.Fill(Ds, "SpecialColor")
        OrderNoTxt.DataBindings.Add(New Binding("Text", Ds, "SpecialColor.OrderNo"))
        PrintOntxt.DataBindings.Add(New Binding("Text", Ds, "SpecialColor.PrintOn"))
        SpColortxt.DataBindings.Add(New Binding("Text", Ds, "SpecialColor.SpecialColor"))
        Colortxt.DataBindings.Add(New Binding("Text", Ds, "SpecialColor.color"))
        RefTxt.DataBindings.Add(New Binding("Text", Ds, "SpecialColor.Ref"))
    End Sub

    Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
    Sub SaveData()

        If Ds.Tables("SpecialColor").AsEnumerable().Count(Function(row) row.Field(Of String)("Ref").ToLower() = Trim(RefTxt.Text.ToLower())) > 0 Then
            MsgBox("Order added Before !", MsgBoxStyle.Information)
            Return
        End If
        Dim CurRec As Integer
        CurRec = Me.BindingContext(Ds, "SpecialColor").Position
        Dim OrderNo As String = Ds.Tables("SpecialColor").Rows(CurRec).Item("OrderNo")
        Dim PrintOn As String = Ds.Tables("SpecialColor").Rows(CurRec).Item("PrintOn")
        Dim SpColor As String = Ds.Tables("SpecialColor").Rows(CurRec).Item("SpecialColor")

        Ds.Tables("SpecialColor").Rows(CurRec).BeginEdit()
        Ds.Tables("SpecialColor").Rows(CurRec).Item("color") = Me.Colortxt.Text
        Ds.Tables("SpecialColor").Rows(CurRec).Item("Ref") = Me.RefTxt.Text
        Da.UpdateCommand = New OleDbCommand("Update SpecialColor Set Color=?,Ref=? Where OrderNo=? And PrintOn=? And SpecialColor=? ", Con)
        Da.UpdateCommand.Parameters.Clear()
        Da.UpdateCommand.Parameters.AddWithValue("?", Me.Colortxt.Text.ToString)
        Da.UpdateCommand.Parameters.AddWithValue("?", Me.RefTxt.Text.ToString)
        Da.UpdateCommand.Parameters.AddWithValue("?", OrderNo)
        Da.UpdateCommand.Parameters.AddWithValue("?", PrintOn)
        Da.UpdateCommand.Parameters.AddWithValue("?", SpColor)
        Ds.Tables("SpecialColor").Rows(CurRec).EndEdit()




        Da.Update(Ds, "SpecialColor")
      


    End Sub
    Private Sub First_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles First.Click
        Me.BindingContext(Ds, "SpecialColor").Position = 0
    End Sub

    Private Sub Perv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Perv.Click
        Me.BindingContext(Ds, "SpecialColor").Position -= 1
    End Sub

    Private Sub Next1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Next1.Click
        Me.BindingContext(Ds, "SpecialColor").Position += 1
    End Sub

    Private Sub Last_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Last.Click
        Dim mngr As BindingManagerBase = Me.BindingContext(Ds, "SpecialColor")
        mngr.Position = mngr.Count - 1
    End Sub

    Private Sub New1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles New1.Click
        Dim result = MessageBox.Show("you sure you want to Exit ? ", "caption", MessageBoxButtons.YesNo)
        If result = DialogResult.Yes Then
            MyBase.Close()
        End If
    End Sub

    Private Sub Finish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Finish.Click
        Dim result = MessageBox.Show("Did you want to Save your data before Exit ? ", "caption", MessageBoxButtons.YesNo)
        If result = DialogResult.Yes Then
            SaveData()
            MyBase.Close()
        ElseIf result = DialogResult.No Then
            MyBase.Close()

        End If
    End Sub

    Private Sub Previous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Previous.Click
        PrintDetails.Show()
        MyBase.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        




        If Me.BindingContext(Ds, "SpecialColor").Position = Me.BindingContext(Ds, "SpecialColor").Count - 1 Then
            SaveData()
            Me.Close()
        Else
            SaveData()
            Me.BindingContext(Ds, "SpecialColor").Position += 1

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


الردود في هذا الموضوع
Object reference not set to an instance of an object. - بواسطة ahmedshafea - 18-10-13, 04:34 AM

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


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