In addbuyer
, Dim newbox As TextBox
is nothing and that's the cause of the error.
You added all the textbox controls to boxes
so you need to loop thru that when you insert into the DB. One way to do it is by looping and passing each textbox by reference:
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
For Each t As TextBox In boxes
addbuyer(t)
Next
End Sub
Private Sub addbuyer(ByRef newbox As TextBox)
Try
datab = " Insert INTO sample (sample1) values ( '" & newbox.Text & "')"
connDB()
cmd = New OleDbCommand(datab, conn)
Dim i As Integer
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Added SUccesfully", MsgBoxStyle.Information, "Confirmation")
Else
MsgBox("Failed Adding", MsgBoxStyle.Information, "Alert!")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…