codice:
Dim str as string = "Database=CURRICULUM;Server=xxx.xxx.xxx.xxx;user ID=xxx;pwd=xxx"
                Dim conn as new SqlConnection(str)
                conn.open
                Dim SQL2 = "SELECT MAX(ID_PARENTI) FROM PARENTI"
                Dim cmd2 as New SqlCommand(sql2, conn)
                Dim dr2 as  SqlDataReader = cmd2.ExecuteReader()
				If IsNothing(dr2.read()) then
					Session("parenti") = 1
				else
					While dr2.read()
						Dim par as integer = dr2.Item(0)
						Dim id_par as integer = par + 1
						Session("parenti") = id_par
					end while
				end if
                dr2.close()
Mi dovrebbe restituire:
se c'è gia qualche record Session("parenti") = 1
altrimenti session("parenti") = ultimo_record + 1
però non va
dà questo errore:
Server Error in '/wcv' Application.
--------------------------------------------------------------------------------

Prepared statement '(@id int,@nome_p varchar(3),@nome_m varchar(4),@nome_b varchar(3' expects parameter @id, which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Prepared statement '(@id int,@nome_p varchar(3),@nome_m varchar(4),@nome_b varchar(3' expects parameter @id, which was not supplied.

Source Error:


Line 95: cmd.Parameters.add("@pro_c2", sqldbtype.varchar).value = cld2job.text
Line 96: cmd.Parameters.add("@cong", sqldbtype.varchar).value = cONGIUNTI.text
Line 97: cmd.ExecuteNonQuery
Line 98: ' RECUPERO DATO ULTIMO RECORD TABELLA ### MILITARE ###
Line 99: Dim SQL3 = "SELECT MAX(ID_MILIT) FROM MILITARE"


Source File: D:\Wcv\index.aspx Line: 97

Stack Trace:


[SqlException: Prepared statement '(@id int,@nome_p varchar(3),@nome_m varchar(4),@nome_b varchar(3' expects parameter @id, which was not supplied.]
System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +194
ASP.index_aspx.bangbang(Object sender, EventArgs e) in D:\Wcv\index.aspx:97
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
cosa può essere?