Lincemiope
New member
- Joined
- Jul 20, 2010
- Messages
- 1
- Programming Experience
- 1-3
Hi, i'm new here and i don't know if i'm posting in the right area, if i'm not i'm sorry. I'm not very good in database-interaction, and searching the internet for a tutorial i found some code i tried to modify to be useful for what i have to do, the problem is that when i press the button to save the work, an error appears telling me that the operation failed. Unfortunately the names aren't in english so if you have some question just ask but the structure is clear. I attach the code and hope you can tell me what's wrong and how to fix it thanks.
VB.NET:
Private Sub inserisci_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inserisci.MouseClick
Dim objconn As OleDbConnection
Dim stringaconn As String
Dim stringasql As String
Dim objcomm As OleDbCommand
stringaconn = "Provider=Microsoft.JET.OLEDB.4.0;Data Source="
stringaconn = stringaconn & App_Path() & "\db.mdb"
objconn = New OleDbConnection(stringaconn)
objconn.Open()
stringasql = "Insert into contatti(nome,cognome,indirizzo,civico,interno,cap,citta,provincia,telefono,cellulare,fax,email) values('"
stringasql = stringasql & Me.tnome.Text & "'" & ","
stringasql = stringasql & "'" & Me.tcognome.Text & "'" & ","
stringasql = stringasql & "'" & Me.tindirizzo.Text & "'" & ","
stringasql = stringasql & "'" & Me.tcivico.Text & "'" & ","
stringasql = stringasql & "'" & Me.tinterno.Text & "'" & ","
stringasql = stringasql & "'" & Me.tcap.Text & "'" & ","
stringasql = stringasql & "'" & Me.tcitta.Text & "'" & ","
stringasql = stringasql & "'" & Me.tprovincia.Text & "'" & ","
stringasql = stringasql & "'" & Me.ttelefono.Text & "'" & ","
stringasql = stringasql & "'" & Me.tcellulare.Text & "'" & ","
stringasql = stringasql & "'" & Me.tfax.Text & "'" & ","
stringasql = stringasql & "'" & Me.temail.Text & "'" & ")"
objcomm = New OleDbCommand(stringasql, objconn)
Dim risputente As Integer
Try
risputente = objcomm.ExecuteNonQuery()
If risputente = 1 Then
MsgBox("Inserimento effettuato con successo")
objconn.Close()
Me.tnome.Text = ""
Me.tcognome.Text = ""
Me.tindirizzo.Text = ""
Me.tcivico.Text = ""
Me.tinterno.Text = ""
Me.tcap.Text = ""
Me.tcitta.Text = ""
Me.tprovincia.Text = ""
Me.ttelefono.Text = ""
Me.tcellulare.Text = ""
Me.tfax.Text = ""
Me.temail.Text = ""
Me.tnome.Focus()
End If
Catch es As Exception
MsgBox("L'operazione non è andata a buon fine.")
objconn.Close()
End Try
End Sub