Jump to content

Dat grid in VB.NET

- - - - -

  • Please log in to reply
No replies to this topic

#1
Naveed_786

Naveed_786

    Newbie

  • Members
  • Pip
  • 2 posts
Dear All,

I have problem and stuck on it here is my code which i am using to save record in db the problem is this when the forms loads and i click on save button it gives me message Please enter the required fields fine i want this message but when

1. When i enter the data in 2 or 3 cells then click on save button it saves the record and gives message Please enter the required fields first of all it should not save data in db unless i enter the values for all cells

2. When i insert all values it and click on save button it gives me Please enter the required fields instead of this message it should give message Record has been inserted in db as i am writing in my coding.



Please help me how can i resolve this issue

Thanks in advance.



Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

    Try

      For r = 0 To DataGridView1.RowCount - 2

        For Each cell As DataGridViewCell In DataGridView1.Rows(r).Cells

          If cell.Value Is Nothing OrElse cell.Value.ToString = String.Empty Then

            MessageBox.Show("Please Enter the Required Field(s)!", "ITPCHR", MessageBoxButtons.OK, MessageBoxIcon.Stop)

            Exit Sub

          Else

            Me.Validate()

            Me.myDA.Update(Me.myDataSet.Tables("EQUIPMENT_INV"))

            Me.myDataSet.AcceptChanges()

          End If

        Next

      Next r

      MessageBox.Show("Record Inserted Successfully......", "ITPCHR", MessageBoxButtons.OK, MessageBoxIcon.Information)

      Exit Try

    Catch ex As Exception

      MsgBox(ex.Message)

    End Try

  End Sub





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users