Gisteren kreeg ik een code en deze had ik neergezet alleen haalt deze code de waarden op uit de database alleen ik wil gegevens toevoegen in de database.
Kan iemand mij helpen, zal even het hele stukje code plakken!
Bij: adapter.fill(topics) zegt het ik kan de db niet vinden raar!
Bestaat de DB wel, is het pad ernaar wel correct? In je andere TableAdapter ga je een tabel Klanten ophalen, wat wel lukt. Nu haal je gegevens van de tabel Topics op, bestaat die tabel wel? Kijk dat eens allemaal na!
Imports System.Data.OleDb
Public Class MSPVenster
Private Sub MSPVenster_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MSPDataSet.Klanten' table. You can move, or remove it, as needed.
Me.KlantenTableAdapter.Fill(Me.MSPDataSet.Klanten)
Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MSP.mdb;Persist Security Info=False"
Dim cmd As String = "Select * from Klanten"
Dim adapter As New OleDbDataAdapter(cmd, conn)
Dim topics As New DataSet
adapter.Fill(MSPDataSet.Klanten)
End Sub
Private Sub btnNieuweKlant_Toevoegen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNieuweKlant_Toevoegen.Click
If String.IsNullOrEmpty(BedrijfsnaamTextBox.Text) And String.IsNullOrEmpty(VoornaamTextBox.Text) And String.IsNullOrEmpty(AchternaamTextBox.Text) And String.IsNullOrEmpty(AdresTextBox.Text) And String.IsNullOrEmpty(PostcodeTextBox.Text) And String.IsNullOrEmpty(PlaatsTextBox.Text) Then
MessageBox.Show("Alle velden invullen")
ElseIf Not IsNumeric(TelefoonnummerTextBox.Text) Then
MessageBox.Show("Telefoonnummer mogen alleen getallen worden ingevuld")
Else
Dim myConnection As OleDbConnection = New OleDbConnection(My.MySettings.Default.MSPConnectionString)
Dim strQuery = "INSERT INTO Klanten(Bedrijfsnaam,Voornaam, Achternaam, Adres, Postcode, Plaats, Telefoonnummer, Faxnummer, Emailadres) VALUES('" & BedrijfsnaamTextBox.Text & "', '" & VoornaamTextBox.Text & "', '" & AchternaamTextBox.Text & "', '" & AdresTextBox.Text & "', '" & PostcodeTextBox.Text & "', '" & PlaatsTextBox.Text & "', '" & Convert.ToInt32(TelefoonnummerTextBox.Text) & "', '" & FaxnummerTextBox.Text & "', '" & EmailadresTextBox.Text & "')"
Dim myCommand As New OleDbCommand(strQuery, myConnection)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Volgende fout is opgetreden: " & Environment.NewLine & ex.Message)
Finally
myConnection.Close()
End Try
Me.KlantenTableAdapter.Fill(Me.MSPDataSet.Klanten)
End If
End Sub
End Class
Imports System.Data.OleDb
PublicClass MSPVenster
PrivateSub MSPVenster_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)HandlesMyBase.Load
'TODO: This line of code loads data into the 'MSPDataSet.Klanten' table. You can move, or remove it, as needed.
Imports System.Data.OleDb
Public Class MSPVenster
Private Sub MSPVenster_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KlantenTableAdapter.Fill(Me.MSPDataSet.Klanten)
End Sub
Private Sub btnNieuweKlant_Toevoegen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNieuweKlant_Toevoegen.Click
If String.IsNullOrEmpty(BedrijfsnaamTextBox.Text) And String.IsNullOrEmpty(VoornaamTextBox.Text) And String.IsNullOrEmpty(AchternaamTextBox.Text) And String.IsNullOrEmpty(AdresTextBox.Text) And String.IsNullOrEmpty(PostcodeTextBox.Text) And String.IsNullOrEmpty(PlaatsTextBox.Text) Then
MessageBox.Show("Alle velden invullen")
ElseIf Not IsNumeric(TelefoonnummerTextBox.Text) Then
MessageBox.Show("Telefoonnummer mogen alleen getallen worden ingevuld")
Else
Dim myConnection As OleDbConnection = New OleDbConnection(My.MySettings.Default.MSPConnectionString)
Dim strQuery = "INSERT INTO Klanten(Bedrijfsnaam,Voornaam, Achternaam, Adres, Postcode, Plaats, Telefoonnummer, Faxnummer, Emailadres) VALUES('" & BedrijfsnaamTextBox.Text & "', '" & VoornaamTextBox.Text & "', '" & AchternaamTextBox.Text & "', '" & AdresTextBox.Text & "', '" & PostcodeTextBox.Text & "', '" & PlaatsTextBox.Text & "', '" & Convert.ToInt32(TelefoonnummerTextBox.Text) & "', '" & FaxnummerTextBox.Text & "', '" & EmailadresTextBox.Text & "')"
Dim myCommand As New OleDbCommand(strQuery, myConnection)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Volgende fout is opgetreden: " & Environment.NewLine & ex.Message)
Finally
myConnection.Close()
End Try
Me.KlantenTableAdapter.Fill(Me.MSPDataSet.Klanten)
End If
End Sub
End Class
Imports System.Data.OleDb
PublicClass MSPVenster
PrivateSub MSPVenster_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)HandlesMyBase.Load
komt telkens met record 1 terug!
net alsof als ik op de knop druk, zegt alle textboxen.clear...maar
moet gebeuren dat het in een nieuwe record word gezet...
vreemd...ik snap er niks meer van...zeg ik mail het je wel even!!