Sl Server Express

venerdì 24 marzo 2006 - 15.11

bla Profilo | Newbie

Salve a tutti :)

Ho sviluppato un'applicazione in vb.net piuttosto semplice, utilizzando Sql Server Express 2005. Finchè mi limito a leggere dati dal db non incontro nessun tipo di problema, nel momento in cui, invece, vado ad effettuare delle insert, i record non vengono inseriti all'interno del database. Tuttavia non mi dà nessun errore e la procedura di inserimento sembra andare a buon fine.

Qualche idea? Ve ne sarei eternamente grata !

alx_81 Profilo | Guru

Purtroppo così non posso esserti di aiuto.. ho sql server express e funziona tutto.. se proprio non hai alcun errore a video, probabilmente hai una try catch che gestisce il fallimento dell'inserimento senza dare messaggi.. non saprei proprio cosa dirti di altro..
Se vuoi provare a postare il codice in cui fai la insert..
vedi tu!!

ciao!
Alx81 =)

trinity Profilo | Guru

Strano se non salva i dati da qualche parte esiste un'errore, come ha detto alex_81 posta il codice così gli diamo un'occhiata

Ciao

Cirillo Fabio
www.wondernet.biz
fabio@wondernet.biz
http://blogs.dotnethell.it/fabiocirillo/

bla Profilo | Newbie

Grazie delle risposte :)

Questo è il codice che mi crea problemi:

Public Sub EcmInsAnagraficaPartecipante( _
ByVal Nome As String, _
ByVal Cognome As String, _
ByVal DataNascita As String, _
ByVal CodiceFiscale As String, _
ByVal Professione As String, _
ByVal Disciplina As String, _
ByVal Indirizzo As String, _
ByVal Provincia As String, _
ByVal Comune As String, _
ByVal Cap As String, _
ByVal Telefono As String, _
ByVal Cellulare As String, _
ByVal Email As String, _
ByVal EnteAppartenenza As String, _
ByVal DataModifica As String, _
ByVal LuogoNascita As String)

Dim connection = New System.Data.SqlClient.SqlConnection
connection.ConnectionString = Global.ECManagerWin.My.MySettings.Default.KERBI_DataConnectionString
Dim Command = New System.Data.SqlClient.SqlCommand

Command.Connection = connection
Command.CommandText = "InsAnagrafica"
Command.CommandType = System.Data.CommandType.System.Data.CommandType.StoredProcedure
'1
Command.Parameters.Add(New SqlParameter("@Nome", SqlDbType.VarChar))
If (Nome = "") Then
Command.Parameters("@Nome").Value = System.DBNull.Value
Else
Command.Parameters("@Nome").Value = CType(Nome, String)
End If
'2
Command.Parameters.Add(New SqlParameter("@Cognome", SqlDbType.VarChar))
If (Cognome = "") Then
Command.Parameters("@Cognome").Value = System.DBNull.Value
Else
Command.Parameters("@Cognome").Value = CType(Cognome, String)
End If
'3
Command.Parameters.Add(New SqlParameter("@DataNascita", SqlDbType.DateTime))
If (DataNascita <> "") Then
Command.Parameters("@DataNascita").Value = CType(DataNascita, Date)
Else
Command.Parameters("@DataNascita").Value = System.DBNull.Value
End If
'4
Command.Parameters.Add(New SqlParameter("@CodiceFiscale", SqlDbType.NVarChar))

If (CodiceFiscale = "") Then
Command.Parameters("@CodiceFiscale").Value = System.DBNull.Value
Else
Command.Parameters("@CodiceFiscale").Value = CType(CodiceFiscale, String)
End If
'5
Command.Parameters.Add(New SqlParameter("@Professione", SqlDbType.Int))
If (Professione <> "") Then
Command.Parameters("@Professione").Value = CType(Professione, Integer)
Else
Command.Parameters("@Professione").Value = System.DBNull.Value
End If
'6
Command.Parameters.Add(New SqlParameter("@Disciplina", SqlDbType.Int))
If (Disciplina <> "") Then
Command.Parameters("@Disciplina").Value = CType(Disciplina, Integer)
Else
Command.Parameters("@Disciplina").Value = System.DBNull.Value
End If
'7
Command.Parameters.Add(New SqlParameter("@Indirizzo", SqlDbType.VarChar))

If (Indirizzo = "") Then
Command.Parameters("@Indirizzo").value = System.DBNull.Value
Else
Command.Parameters("@Indirizzo").value = CType(Indirizzo, String)
End If
'8
Command.Parameters.Add(New SqlParameter("@Provincia", SqlDbType.Int))
If (Provincia <> "") Then
Command.Parameters("@Provincia").Value = CType(Provincia, Integer)
Else
Command.Parameters("@Provincia").Value = System.DBNull.Value
End If
'9
Command.Parameters.Add(New SqlParameter("@Comune", SqlDbType.Int))
If (Comune <> "") Then
Command.Parameters("@Comune").value = CType(Comune, Integer)
Else
Command.Parameters("@Comune").value = System.DBNull.Value
End If
'10
Command.Parameters.Add(New SqlParameter("@Cap", SqlDbType.NVarChar))
If (Cap = "") Then
Command.Parameters("@Cap").value = System.DBNull.Value
Else
Command.Parameters("@Cap").value = CType(Cap, String)
End If

'11
Command.Parameters.Add(New SqlParameter("@Telefono", SqlDbType.NVarChar))
If (Telefono = "") Then
Command.Parameters("@Telefono").value = System.DBNull.Value
Else
Command.Parameters("@Telefono").value = CType(Telefono, String)
End If
'12
Command.Parameters.Add(New SqlParameter("@Cellulare", SqlDbType.NVarChar))
If (Cellulare = "") Then
Command.Parameters("@Cellulare").Value = System.DBNull.Value
Else
Command.Parameters("@Cellulare").Value = CType(Cellulare, String)
End If
'13
Command.Parameters.Add(New SqlParameter("@Email", SqlDbType.VarChar))
If (Email = "") Then
Command.Parameters("@Email").Value = System.DBNull.Value
Else
Command.Parameters("@Email").Value = CType(Email, String)
End If
'14
Command.Parameters.Add(New SqlParameter("@EnteAppartenenza", SqlDbType.VarChar))
If (EnteAppartenenza = "") Then
Command.Parameters("@EnteAppartenenza").Value = System.DBNull.Value
Else
Command.Parameters("@EnteAppartenenza").Value = CType(EnteAppartenenza, String)
End If
'15
Command.Parameters.Add(New SqlParameter("@DataModifica", SqlDbType.DateTime))
If (DataModifica <> "") Then
Command.Parameters("@DataModifica").Value = CType(DataModifica, Date)
Else
Command.Parameters("@DataModifica").Value = System.DBNull.Value
End If
'16
Command.Parameters.Add(New SqlParameter("@LuogoNascita", SqlDbType.VarChar))
If (LuogoNascita = "") Then
Command.Parameters("@LuogoNascita").Value = System.DBNull.Value
Else
Command.Parameters("@LuogoNascita").Value = CType(LuogoNascita, String)
End If

Dim previousConnectionState As System.Data.ConnectionState = Command.Connection.State
If ((Command.Connection.State And System.Data.ConnectionState.Open) _
<> System.Data.ConnectionState.Open) Then
Command.Connection.Open()
End If

Try
Dim myTrans As SqlTransaction
myTrans = connection.BeginTransaction()


Command.Transaction = myTrans

Dim rows As Integer = Command.ExecuteNonQuery()

myTrans.Commit()

If rows = 1 Then

MessageBox.Show("NUOVO MEDICO!")

Else

MessageBox.Show("NESSUN INSERIMENTO!")

End If

Catch exp As SqlClient.SqlException
MsgBox(exp.Message)
Finally
If (previousConnectionState = System.Data.ConnectionState.Closed) Then
Command.Connection.Close()
End If
End Try

End Sub

trinity Profilo | Guru

>Grazie delle risposte :)
>
>Questo è il codice che mi crea problemi:
>
>Public Sub EcmInsAnagraficaPartecipante( _
> ByVal Nome As String, _
> ByVal Cognome As String, _
> ByVal DataNascita As String, _
> ByVal CodiceFiscale As String, _
> ByVal Professione As String, _
> ByVal Disciplina As String, _
> ByVal Indirizzo As String, _
> ByVal Provincia As String, _
> ByVal Comune As String, _
> ByVal Cap As String, _
> ByVal Telefono As String, _
> ByVal Cellulare As String, _
> ByVal Email As String, _
>ByVal EnteAppartenenza As String, _
> ByVal DataModifica As String, _
> ByVal LuogoNascita As String)
>
>Dim connection = New System.Data.SqlClient.SqlConnection
>connection.ConnectionString = Global.ECManagerWin.My.MySettings.Default.KERBI_DataConnectionString
> Dim Command = New System.Data.SqlClient.SqlCommand
>
> Command.Connection = connection
> Command.CommandText = "InsAnagrafica"
>Command.CommandType = System.Data.CommandType.System.Data.CommandType.StoredProcedure
> '1
>Command.Parameters.Add(New SqlParameter("@Nome", SqlDbType.VarChar))
> If (Nome = "") Then
>Command.Parameters("@Nome").Value = System.DBNull.Value
> Else
>Command.Parameters("@Nome").Value = CType(Nome, String)
> End If
> '2
>Command.Parameters.Add(New SqlParameter("@Cognome", SqlDbType.VarChar))
> If (Cognome = "") Then
>Command.Parameters("@Cognome").Value = System.DBNull.Value
> Else
>Command.Parameters("@Cognome").Value = CType(Cognome, String)
> End If
> '3
>Command.Parameters.Add(New SqlParameter("@DataNascita", SqlDbType.DateTime))
> If (DataNascita <> "") Then
>Command.Parameters("@DataNascita").Value = CType(DataNascita,
>Date)
> Else
>Command.Parameters("@DataNascita").Value = System.DBNull.Value
> End If
> '4
>Command.Parameters.Add(New SqlParameter("@CodiceFiscale", SqlDbType.NVarChar))
>
> If (CodiceFiscale = "") Then
>Command.Parameters("@CodiceFiscale").Value = System.DBNull.Value
> Else
>Command.Parameters("@CodiceFiscale").Value = CType(CodiceFiscale,
>String)
> End If
> '5
>Command.Parameters.Add(New SqlParameter("@Professione", SqlDbType.Int))
> If (Professione <> "") Then
>Command.Parameters("@Professione").Value = CType(Professione,
>Integer)
> Else
>Command.Parameters("@Professione").Value = System.DBNull.Value
> End If
> '6
>Command.Parameters.Add(New SqlParameter("@Disciplina", SqlDbType.Int))
> If (Disciplina <> "") Then
>Command.Parameters("@Disciplina").Value = CType(Disciplina, Integer)
> Else
>Command.Parameters("@Disciplina").Value = System.DBNull.Value
> End If
> '7
>Command.Parameters.Add(New SqlParameter("@Indirizzo", SqlDbType.VarChar))
>
> If (Indirizzo = "") Then
>Command.Parameters("@Indirizzo").value = System.DBNull.Value
> Else
>Command.Parameters("@Indirizzo").value = CType(Indirizzo, String)
> End If
> '8
>Command.Parameters.Add(New SqlParameter("@Provincia", SqlDbType.Int))
> If (Provincia <> "") Then
>Command.Parameters("@Provincia").Value = CType(Provincia, Integer)
> Else
>Command.Parameters("@Provincia").Value = System.DBNull.Value
> End If
> '9
>Command.Parameters.Add(New SqlParameter("@Comune", SqlDbType.Int))
> If (Comune <> "") Then
>Command.Parameters("@Comune").value = CType(Comune, Integer)
> Else
>Command.Parameters("@Comune").value = System.DBNull.Value
> End If
> '10
>Command.Parameters.Add(New SqlParameter("@Cap", SqlDbType.NVarChar))
> If (Cap = "") Then
>Command.Parameters("@Cap").value = System.DBNull.Value
> Else
>Command.Parameters("@Cap").value = CType(Cap, String)
> End If
>
> '11
>Command.Parameters.Add(New SqlParameter("@Telefono", SqlDbType.NVarChar))
> If (Telefono = "") Then
>Command.Parameters("@Telefono").value = System.DBNull.Value
> Else
>Command.Parameters("@Telefono").value = CType(Telefono, String)
> End If
> '12
>Command.Parameters.Add(New SqlParameter("@Cellulare", SqlDbType.NVarChar))
> If (Cellulare = "") Then
>Command.Parameters("@Cellulare").Value = System.DBNull.Value
> Else
>Command.Parameters("@Cellulare").Value = CType(Cellulare, String)
> End If
> '13
>Command.Parameters.Add(New SqlParameter("@Email", SqlDbType.VarChar))
> If (Email = "") Then
>Command.Parameters("@Email").Value = System.DBNull.Value
> Else
>Command.Parameters("@Email").Value = CType(Email, String)
> End If
> '14
>Command.Parameters.Add(New SqlParameter("@EnteAppartenenza",
>SqlDbType.VarChar))
> If (EnteAppartenenza = "") Then
>Command.Parameters("@EnteAppartenenza").Value = System.DBNull.Value
> Else
>Command.Parameters("@EnteAppartenenza").Value = CType(EnteAppartenenza,
>String)
> End If
> '15
>Command.Parameters.Add(New SqlParameter("@DataModifica", SqlDbType.DateTime))
> If (DataModifica <> "") Then
>Command.Parameters("@DataModifica").Value = CType(DataModifica,
>Date)
> Else
>Command.Parameters("@DataModifica").Value = System.DBNull.Value
> End If
> '16
>Command.Parameters.Add(New SqlParameter("@LuogoNascita", SqlDbType.VarChar))
> If (LuogoNascita = "") Then
>Command.Parameters("@LuogoNascita").Value = System.DBNull.Value
> Else
>Command.Parameters("@LuogoNascita").Value = CType(LuogoNascita,
>String)
> End If
>
>Dim previousConnectionState As System.Data.ConnectionState =
>Command.Connection.State
>If ((Command.Connection.State And System.Data.ConnectionState.Open)
>_
> <> System.Data.ConnectionState.Open) Then
> Command.Connection.Open()
> End If
>
> Try
> Dim myTrans As SqlTransaction
> myTrans = connection.BeginTransaction()
>
>
> Command.Transaction = myTrans
>
> Dim rows As Integer = Command.ExecuteNonQuery()

perchè qui non scrivi solo: command.ExecuteNon Query e se il codice supera la procedura commit significa che il dato è stato salvato e quindi visualizzi il messaggio che è stato inserito un nuovo medico.

>
> myTrans.Commit()
>
> If rows = 1 Then
>
> MessageBox.Show("NUOVO MEDICO!")
>
> Else
>
> MessageBox.Show("NESSUN INSERIMENTO!")
>
> End If
>
> Catch exp As SqlClient.SqlException
> MsgBox(exp.Message)
> Finally
>If (previousConnectionState = System.Data.ConnectionState.Closed)
>Then
> Command.Connection.Close()
> End If
> End Try
>
> End Sub
una cosa non capisco e la tua connectionstring che utilizzi: vai sul mio blog e alla sezione link troverai il collegamento ad un sito internet che tratto ogni tipo di connessione ai database, vai alla sezione sql server 2005, scegli SqlConnection (.NET) e utilizza la connessione con autenticazione windows ossia la Trusted Connection.

Poi volevo dirti che se i campi di tipo varchar nella tua tabella gli imposti accetta il null potresti anche evitare di scrivere le varie if..end if che stabilisci di accettare il valore null

Ciao
Cirillo Fabio
www.wondernet.biz
fabio@wondernet.biz
http://blogs.dotnethell.it/fabiocirillo/
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5