|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dllhappens!! Someone can help me? FIRST QUERY GOES WELL, SECOND BREAK WITH ERROR why? Dim connessione As New SqlClient.SqlConnection("Server=SOSQLSRV01;Initial Catalog=SO_Bolle;Uid=SO_CattolicaRE;PWD=sogeda") Dim iddestinatario As Integer Dim TestoQueryCodicecodicedestinario As String = "SELECT max(id_destinatario) FROM destinatario " Dim QueryCodicecodicedestinario As New SqlClient.SqlCommand(TestoQueryCodicecodicedestinario, Connessione) Dim LettoreCodicecodicedestinario As SqlClient.SqlDataReader If Connessione.State = ConnectionState.Closed Then Connessione.Open() End If LettoreCodicecodicedestinario = QueryCodicecodicedestinario.ExecuteReader() LettoreCodicecodicedestinario.Read() Dim Codcodicedestinario As String = LettoreCodicecodicedestinario.GetInt32(0) LettoreCodicecodicedestinario.Close() Connessione.Close() Dim QuerySalvadestinatario As String = "INSERT INTO Destinatario (Intestazione) VALUES ('ciao')" Dim Inseriscidestinatario As New SqlClient.SqlCommand(QuerySalvadestinatario, connessione) If connessione.State = ConnectionState.Closed Then connessione.Open() End If Inseriscidestinatario.ExecuteNonQuery() connessione.Close() Rampa,
Be aware that this kind of code can be very problemfull in a multiuser environment where more users can add rows. I would use the new Guid as the uniqueidentifier. As well, as you want to get one value than the command.executescalar is much better. http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx And when you want to see what was your error than embed your commands inside a Try Catch block Try result = cmd.executescalar Catch sqlex as sqlexception messagebox.show(sqlex.tostring) Catch ex as exception messagebox.show(ex.toString End Try I hope this helps, Cor Show quoteHide quote "Rampa" <on***@libero.it> schreef in bericht news:1153126676.767257.268520@m79g2000cwm.googlegroups.com... > hello! the problem is always the same but i can't understand why it > happens!! Someone can help me? FIRST QUERY GOES WELL, SECOND BREAK WITH > ERROR why? > > Dim connessione As New > SqlClient.SqlConnection("Server=SOSQLSRV01;Initial > Catalog=SO_Bolle;Uid=SO_CattolicaRE;PWD=sogeda") > Dim iddestinatario As Integer > > Dim TestoQueryCodicecodicedestinario As String = "SELECT > max(id_destinatario) FROM destinatario " > Dim QueryCodicecodicedestinario As New > SqlClient.SqlCommand(TestoQueryCodicecodicedestinario, Connessione) > Dim LettoreCodicecodicedestinario As SqlClient.SqlDataReader > If Connessione.State = ConnectionState.Closed Then > Connessione.Open() > End If > LettoreCodicecodicedestinario = > QueryCodicecodicedestinario.ExecuteReader() > LettoreCodicecodicedestinario.Read() > Dim Codcodicedestinario As String = > LettoreCodicecodicedestinario.GetInt32(0) > LettoreCodicecodicedestinario.Close() > Connessione.Close() > > > Dim QuerySalvadestinatario As String = "INSERT INTO > Destinatario (Intestazione) VALUES ('ciao')" > Dim Inseriscidestinatario As New > SqlClient.SqlCommand(QuerySalvadestinatario, connessione) > If connessione.State = ConnectionState.Closed Then > connessione.Open() > End If > Inseriscidestinatario.ExecuteNonQuery() > connessione.Close() > Thank you! Really!! I solved the problem!
Be aware that this kind of code can be very problemfull in a multiuser environment where more users can add rows. Can you explain me why you say it? Thank you again! Cor Ligthert [MVP] ha scritto: Show quoteHide quote > Rampa, > > Be aware that this kind of code can be very problemfull in a multiuser > environment where more users can add rows. > > I would use the new Guid as the uniqueidentifier. > > As well, as you want to get one value than the command.executescalar is much > better. > > http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx > > And when you want to see what was your error than embed your commands inside > a Try Catch block > > Try > result = cmd.executescalar > Catch sqlex as sqlexception > messagebox.show(sqlex.tostring) > Catch ex as exception > messagebox.show(ex.toString > End Try > > I hope this helps, > > Cor > > "Rampa" <on***@libero.it> schreef in bericht > news:1153126676.767257.268520@m79g2000cwm.googlegroups.com... > > hello! the problem is always the same but i can't understand why it > > happens!! Someone can help me? FIRST QUERY GOES WELL, SECOND BREAK WITH > > ERROR why? > > > > Dim connessione As New > > SqlClient.SqlConnection("Server=SOSQLSRV01;Initial > > Catalog=SO_Bolle;Uid=SO_CattolicaRE;PWD=sogeda") > > Dim iddestinatario As Integer > > > > Dim TestoQueryCodicecodicedestinario As String = "SELECT > > max(id_destinatario) FROM destinatario " > > Dim QueryCodicecodicedestinario As New > > SqlClient.SqlCommand(TestoQueryCodicecodicedestinario, Connessione) > > Dim LettoreCodicecodicedestinario As SqlClient.SqlDataReader > > If Connessione.State = ConnectionState.Closed Then > > Connessione.Open() > > End If > > LettoreCodicecodicedestinario = > > QueryCodicecodicedestinario.ExecuteReader() > > LettoreCodicecodicedestinario.Read() > > Dim Codcodicedestinario As String = > > LettoreCodicecodicedestinario.GetInt32(0) > > LettoreCodicecodicedestinario.Close() > > Connessione.Close() > > > > > > Dim QuerySalvadestinatario As String = "INSERT INTO > > Destinatario (Intestazione) VALUES ('ciao')" > > Dim Inseriscidestinatario As New > > SqlClient.SqlCommand(QuerySalvadestinatario, connessione) > > If connessione.State = ConnectionState.Closed Then > > connessione.Open() > > End If > > Inseriscidestinatario.ExecuteNonQuery() > > connessione.Close() > > Rampa,
> Think that both users want to add a row, the both ask for the last and get > Be aware that this kind of code can be very problemfull in a multiuser > environment where more users can add rows. > > Can you explain me why you say it? > > Thank you again! > that in almost the same time. Than they are both inserting in my idea (id I did understand your code well), the same id. Cor
Bug or Feature? CancelButton vs Escape Key
overides/loads usage Problems using Me.Scale in Framework 2.0 ListView and ImageList/ImageKey Holding down a key HELP: Problem Hosting the "Simplest" of VB.NET Apps enforce event calling on inherited classes detect if running on a terminal server Deleting files using wildcards text editor |
|||||||||||||||||||||||