I'm trying to a create a windows form application in vb.net using a access database (2010) with 2 tables (as the main idea, I'm trying to create a bank creditation application). One table I use it for login, and another one to insert elements into it from a windows form.
For the login table, everything works fine, but when it comes for the second table (clients) I encounter some problems.
The table details for the clients is: ID (autonumber), first name (text), last name (text), PID (number), adress (text), city (text), marital status (text), nochildren (number), date (date/time).
I've created an insert query for the clients table that goes like this:
INSERT INTO `Clienti` (`nume`, `prenume`, `cnp`, `adresa`, `localitate`, `stare civila`) VALUES (?, ?, ?, ?, ?, ?, ?, ?).
In the Windows form I've created I have the following elements: first name (textbox), last name (textbox), PID (textbox), adress (text), city (text), marital status (text) and a button that should save those into my clients table.
The code for the save to DB button is:
Convert.ToInt32(cnptxt.Text)
Convert.ToInt32(numarcopiitxt.Text)
Dim cnpp As Integer
cnpp = Val(cnptxt.Text)
Dim nrcopii As Integer
nrcopii = Val(numarcopiitxt.Text)
Dim nume As String
Dim prenume As String
Dim cnp As Integer
Dim varsta As Integer
Dim adresa As String
Dim localitate As String
Dim starecivila As String
Dim numarcopii As Integer
nume = numetxt.Text
prenume = prenumetxt.Text
cnp = cnpp
varsta = varstatxt.Text
adresa = adresatxt.Text
localitate = localitatetxt.Text
starecivila = starecivilatxt.Text
numarcopii = numarcopiitxt.Text
If Me.ClientiTableAdapter.InsertQueryClienti(nume, prenume, cnp, varsta, adresa, localitate, starecivilatxt.Text) Then
MsgBox("Client adaugat cu succes in baza de date")
Else
MsgBox("O eroare a fost intalnita intr-unul din campurile completate. Reincercati!")
End If
I know it's incomplete when compared with the rows from the clients table, it's due to the problems I've encountered with the save to DB. When I run the application and I tap on the save to DB button, I receive the following error:
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string "necasatorit" to type 'Integer' is not valid.
The code for InsertQueryClienti is INSERT INTO Clienti
(nume
, prenume
, cnp
, adresa
, localitate
, stare civila
) VALUES (?, ?, ?, ?, ?, ?, ?, ?) and the definition for it is Public Overloads Overridable Function InsertQueryClienti(ByVal nume As String, ByVal prenume As String, ByVal cnp As Global.System.Nullable(Of Integer), ByVal adresa As String, ByVal localitate As String, ByVal stare_civila As String, ByVal numarcopii As Global.System.Nullable(Of Integer)) As Integer
necasatorit is referring to the marital status textbox. I can't understand why it gives me that error since the textbox obviously is a string and in the table that row is set as text.