ho notato questo:
togliendo tutti i riferimenti a cognome, mi da lo stesso errore su email. perciò c'è qualcosa che non va da qualche parte:
codice:
Sub InsertBtn_Click(Sender As Object, E As EventArgs)
'Apro la connessione
Dim StrConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=Agenda")
'Creo la query
Dim StrQuery As String = "SELECT ID FROM Admin WHERE Nome='"& Replace(Nome.Text, "'", "''") &"' AND Cognome='"& Replace(Cognome.Text, "'", "''") &"' AND Email='"& Replace(Email.Text, "'", "''") &"' "
Dim myCommand As New SqlCommand(StrQuery , StrConn)
myCommand.Connection.Open()
dim myID as Int64 = myCommand.ExecuteScalar()
if (myID<>0) then
lblMessage.Text = "Record gia esistente"
else
' inserisco il record
StrQuery = "INSERT INTO CLIENTI (Nome, Cognome, Città, Via, Civico, Cap, Tel, Email) VALUES ('"& Nome.Text &"','"& Cognome.Text &"','"& Città.Text &"', '"& Indirizzo.Text &"', "& Civico.Text &", "& Cap.Text &", '"& Tel.Text &"', '"& Email.Text &"')"
MyCommand = New SqlCommand(StrQuery, StrConn)
Try
MyCommand.ExecuteNonQuery()
lblMessage.Text = "INSERITO"
Catch Exc As SQLException
lblMessage.Text = "ERRORE NELLA QUERY"
End Try
MyCommand.Connection.Close()
end if
myCommand.Connection.Close()
StrConn.Close()
End Sub