Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Manejo de nulos

0 views
Skip to first unread message

Felipe CR

unread,
Feb 11, 2009, 9:28:53 AM2/11/09
to
Holan muchachos y muchachas

Estoy usando la siguiente funcion:


Public Shared Function BuscarPrecioVariedad(ByVal IdCustomer As
String, ByVal Variedad As String, ByVal Cultivo As String) As String
Dim SQL As String
Dim precio As String
Dim ConSQL As SqlClient.SqlConnection = New
SqlClient.SqlConnection()
Dim CommSQL As SqlClient.SqlCommand = New
SqlClient.SqlCommand
()


'Busca que existan las tres combinaciones posibles
SQL = "Select price from EXP_PRICES where IdCliente = @Cust
and IdCultivo = @Var and IdVariedad = @planta"
ConSQL.ConnectionString = "Data Source=" + Main.Servidor +
";Initial Catalog=" + Main.GlobalDB + ";Integrated Security=True"
' Abrimos la conexion
ConSQL.Open()
CommSQL.Connection = ConSQL
'Asignamos la consulta que queremos hacer
CommSQL.CommandText = SQL
'Creamos y asignamos valor a los parametros
CommSQL.Parameters.Add("@Cust", SqlDbType.SmallInt)
CommSQL.Parameters("@Cust").Value = IdCustomer
CommSQL.Parameters.Add("@planta", SqlDbType.SmallInt)
CommSQL.Parameters("@planta").Value = Variedad
CommSQL.Parameters.Add("@Var", SqlDbType.SmallInt)
CommSQL.Parameters("@Var").Value = Cultivo
precio = CommSQL.ExecuteScalar.ToString()
If precio.Length > 0 Then
Return precio
Else
'Busca la combinacion de Cliente y Variedad
SQL = "Select price from EXP_PRICES where IdCliente =
@Cust and IdCultivo = @Var"
CommSQL.CommandText = SQL
CommSQL.Parameters.Add("@Cust", SqlDbType.SmallInt)
CommSQL.Parameters("@Cust").Value = IdCustomer
CommSQL.Parameters.Add("@Var", SqlDbType.SmallInt)
CommSQL.Parameters("@Var").Value = Cultivo
precio = CommSQL.ExecuteScalar.ToString()
If precio.Length > 0 Then
Return precio
Else
' Aqui busca la combinacion de cliente y planta
SQL = "Select price from EXP_PRICES where IdCliente =
@Cust and IdVariedad = @planta"
CommSQL.CommandText = SQL
CommSQL.Parameters.Add("@Cust", SqlDbType.SmallInt)
CommSQL.Parameters("@Cust").Value = IdCustomer
CommSQL.Parameters.Add("@planta", SqlDbType.SmallInt)
CommSQL.Parameters("@planta").Value = Variedad
precio = CommSQL.ExecuteScalar.ToString()
If precio.Length > 0 Then
Return precio
Else
' Busca el precio para cliente
SQL = "Select price from EXP_PRICES where
IdCliente = @Cust"
CommSQL.CommandText = SQL
CommSQL.Parameters.Add("@Cust",
SqlDbType.SmallInt)
CommSQL.Parameters("@Cust").Value = IdCustomer
precio = CommSQL.ExecuteScalar.ToString()
If precio.Length > 0 Then
Return precio
Else
' Buscar el precio por variedad
SQL = "Select price from EXP_PRICES where
IdCultivo = @Var"
CommSQL.CommandText = SQL
CommSQL.Parameters.Add("@Var",
SqlDbType.SmallInt)
CommSQL.Parameters("@Var").Value = Cultivo
precio = CommSQL.ExecuteScalar.ToString()
If precio.Length > 0 Then
Return precio
Else
' Busca el precio por planta
SQL = "Select price from EXP_PRICES where
IdVariedad = @planta"
CommSQL.Parameters.Add("@planta",
SqlDbType.SmallInt)
CommSQL.Parameters("@planta").Value =
Variedad
precio = CommSQL.ExecuteScalar.ToString()
If precio.Length > 0 Then
Return precio
Else
Return "0"
End If 'fin de la busqueda por planta
End If ' fin de consulta por variedad
End If 'fin de la consulta de cliente
End If 'fin del if de cliente y planta
End If 'fin del if de Cliente y variedad
End If 'fin del if de la combinacion de las tres variedades
'Cerramos la conexion
ConSQL.Close()
End Function


Como veran, voy haciendo comparaciones


If precio.Length > 0 Then
Return precio
Else
' Aqui busca la combinacion de cliente y planta
SQL = "Select price from EXP_PRICES where IdCliente =
@Cust and IdVariedad = @planta"
CommSQL.CommandText = SQL
CommSQL.Parameters.Add("@Cust", SqlDbType.SmallInt)
CommSQL.Parameters("@Cust").Value = IdCustomer
CommSQL.Parameters.Add("@planta", SqlDbType.SmallInt)
CommSQL.Parameters("@planta").Value = Variedad
precio = CommSQL.ExecuteScalar.ToString()
If precio.Length > 0 Then
Return precio
Else
end if
End if


La idea, es que si no devolvio nada, el primer if, pase al segundo y
si ese tambien, devolvio nada, que pase al siguiente:


Pero si llega al primero y no habia nada, hasta ahi llega...


Como puedo solucionar ese problema, es que la verdad soy bastante
nuevo, en .net y todavia no lo manejo bien.


Gracias de antemano por su ayuda.

0 new messages