.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Return values on VB.NET functions

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :ASP.Net
 

I have been reading that a value needs to be returned by a function, otherwise the following error will occur:

"Function <function name> doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used."

The cure, I have found, is to return something (i.e. "Return 0") before exiting the function. Can someone please enlighten me as to why this might be useful? Can I pass this return value back to the routine that called the function? If so, how do I code this?

Most of the time, however, I find I'm not needing to return a value anyway, and just end up adding "0" to the ends of all my Return statements. Does anyone have any comments on this?

Links referred to:

http://msdn.microsoft.com/en-us/library/87x5f80y%28VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/2e34641s%28v=VS.80%29.aspx
http://forums.asp.net/p/1057272/1507771.aspx

Thanks!





View Complete Post


More Related Resource Links

Writing Webservice return values to table within SQL CLR

  
Visual Studio 2010/Sql Server 2005/ .net 3.5/ C# I have compiled and created assemblies and all works fine when all I do is .pipe.send.   I have changed it now to capture the values in local parameters so I can write to a sql table on the same server.  I have the connection to the database and the table created.  The code compiles fine but when I run it from sql I get the following error.  The code follows the error.   Msg 6522, Level 16, State 1, Procedure CventSP, Line 0 A .NET Framework error occurred during execution of user-defined routine or aggregate "CventSP": System.Data.SqlClient.SqlException: Incorrect syntax near '@eventtitle'. System.Data.SqlClient.SqlException: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnectionSmi.EventSink.DispatchMessages(Boolean ignoreNonFatalMessages) at Microsoft.SqlServer.Server.SmiEventSink_Default.DispatchMessages(Boolean ignoreNonFatalMessages) at System.Data.SqlClient.SqlCommand.RunExecuteNonQuerySmi(Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at StoredP

Getting VP.NET code to respond to SQL Return values and Error Codes

  

I have SQL stored procedures that will return values depending on the outcome of its execution. I have the following code at the end of each of my Stored Procedures:

RETURN @siReturnValue

It would be great to be able to use this Return value after running the Stored Procedures from my VB.NET code. I have included an example of how I am running SQL Stored Procedures below:

    Public Function SearchKeyword(ByVal SearchString As String) As Data.DataTable
        Dim AerialConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("aerialConnectionString").ConnectionString)
        Dim MediaArchive As New Data.DataTable
        Dim reader As SqlDataReader
        
        Try
            AerialConnection.Open()
            Dim SelectMediaArchiveCommand = New SqlCommand("EXEC spSearch @keywords", AerialConnection)
            SelectMediaArchiveCommand.Parameters.AddWithValue("keywords", SearchString)
            reader = SelectMediaArchiveCommand.ExecuteReader()
            MediaArchive.Load(reader)
        Catch e As Exception
        Finally
            AerialConnection.Close()
        End Try
        Return MediaArchive
    End Function

How can I code this to respond to different Return values, or even error cod

Capturing USB Barcode Scanner Return values

  

Hi

We are using USB barcode scanner to scan material barcode labels. These lables are from our vendors.

We does not have control over the label generation. We are using USB barcode scanner for scanning purpose. We want to capture USB barcode scanner output. Normally the scanner returns output in the place holder in which the cursor present.

But we do not put writable text box for the cursor. Instead of write allowable text box we want to put locked or readonly text box in the screen and want to capture scanner value.

How can we do?

Assume that our barcode scanner does not support serial ports.

Regards
S. Muhilan


Muhilan

encoding function parameters and return values when binaryMessageEncoding is used

  

Dear All,

I'm creating simple web service that will accept some parameters (such as customer name and file name) and return content of an xml file as a string and WS client will save it on his side. I'm using custom binding with binaryMessageEncoding and httpTransport. The question is if it is possible to have these input parameters as well as returned xml content binary encoded somehow?

Thanks in advance for your help!


Dzordz

Return a user and a set of values from the same sproc

  

I have a user table with userID, userName ...the standards.
I also have a "Material" table with materialID, materialName, etc.

I combine these in another table "UsersMaterial" with userID and materialID, depending on which materials the user has chosen (between 0 and 5).

Now I need a stored procedure that returns the user information + the set of materials that is mapped to the user.

But I can't see how I can return one row of user information combined with a set of the user materials? Do I join or can I return a set + one row?


Thanks in advance!

Niklas


How to Access MsiEnumRelatedProducts Return Values?

  

I am using the MsiEnumRelatedProducts function and according to all the articles I should be getting text return values such as:

ERROR_BAD_CONFIGURATION,
ERROR_NO_MORE_ITEMS

But I am only getting numbers returned from the function. I assume I need to use some Enum but I cannot find any example anywhere. I have looked at this article:

http://msdn.microsoft.com/en-us/library/aa370103(VS.85).aspx

But there is no explanation of how to actually get those text return values back?


return values

  

i'm trying to check if the text fields are blank i attached the code below, if i leave both textbox blank, both alerts pop up but confirm

how to make it like if the first textbox is blank, alert pop up then exit everything?

 function Validation()
{
if (IsValid()) {
  if (!(confirm("Are you sure you want to save this record?")))
  {
  return false;
  }
return true; 
}


function IsValid()
{
if (!isDate(document.getElementById('txtTest')))
{
alert("Please insert a Date");
return false;
}

if (!isBlank(document.getElementById('txtTest2')))
{
alert("Please insert a Holiday Name ");
return false;
}
return true;
}

asp:button onclientclick="return Validation()"


select query doesnt return values

  

hi all, i need your assistance please.

 

select Comments.Id,SuroundId,ArticleId,PosterId,PostRime,Subject,Body,Visible,Users.Username
from dbo.Comments
inner join Users on Comments.PosterId=Users.Id
where SuroundId=@suround and ArticleId=@articleId


for some reason it doesnt return any values.

before i've added the inner join it worked perfectly.

i couldn't find my mistake, though i passed over it several times.

 

thanks. 


Stored Procedures Only Return integer values?

  

I have the following stored procedure

ALTER PROCEDURE dbo.GetProvMoveModifier
	
	(
	@prov_id int 
	)
	
AS
	DECLARE	   @mod float
	SELECT     @mod = PROV_TYPES.MOVE_MOD
	FROM       PROV_DETAILS INNER JOIN
                      PROV_TYPES ON PROV_DETAILS.TYPE_ID = PROV_TYPES.TYPE_ID
	WHERE      (PROV_DETAILS.PROV_ID = @prov_id)
	RETURN     @mod


MOVE_MOD is defined as a float.


Yet within Dataclasses.designer.cs the function gets added as:

	[Function(Name="dbo.GetProvMoveModifier")]
	public int GetProvMoveModifier([Parameter(DbType="Int")] System.Nullable<int> prov_id)
	{
		IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), prov_id);
		return ((int)(result.ReturnValue));
	}


Naturally this is causing some issues as my C# code needs to handle decimal values.  If I try to manually change the designer code to use floats, I get the following error

'System.Single' is not a valid return type for a mapped stored procedure method.


Any thoughts?  I could setup a work-around, but I would think I could return a decimal value from a stored procedure.


Insert value using Table Value Functions

  
a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

Introduction to Functions

  
A function is a section of code that is used to perform an isolated assignment. Once it has performed its assignment, the function can be accessed to present its result(s).

In Transact-SQL, a function is considered an object. After creating the function object, it becomes part of a database. You can then execute it when necessary.

Built-In Functions Fundamentals

  
While your primary job as a database developer consists of creating lists, probably your second most important job is to assist your users with the various assignments they must perform on your application. One way you can assist is to use functions that perform otherwise complex tasks. We introduced and described functions in the previous lesson. To assist your development with the different tasks of a database, Transact-SQL ships with various already created and tested functions. You just need to be aware of these functions, their syntax, and the results they produce.

Built-in Functions - Text and Image Functions in SQL Server

  
Text and image functions operate on TEXT, NTEXT and IMAGE data types. These data types are deprecated with SQL Server 2005 and should be replaced by VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) when possible. Alternatively you can also consider storing large string values using XML data type. Text and image functions are nondeterministic.

Future versions of SQL Server will not support TEXT, NTEXT and IMAGE data types. Columns with TEXT / NTEXT data type do not support commonly used string functions such as LEN, LEFT, RIGHT, etc. Furthermore, due to the large size of TEXT data you''re likely to see performance issues if you store such data in the database. However, at times you can''t help but use the TEXT / NTEXT / IMAGE data types (for example when supporting 3rd party databases when you cannot change the schema) - this is when text and image functions come in handy.

Date and Time Functions in SQLSERVER

  
Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

1 DATEPART Function
2 DATENAME Function
3 DAY, MONTH, and YEAR Functions
4 GETDATE and GETUTCDATE Functions
5 DATEADD Functions
6 DATEDIFF Function
7 More SQL Server Functions

How to Pass Values Between Web Pages ASP.NET

  
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

Use a query string.

Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

Use session state.

Create public properties in the source page and access the property values in the target page.

Get control information in the target page from controls in the source page.

How to Pass Values Between ASP.NET Web Pages

  
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

Use a query string.

Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

Use session state.

Create public properties in the source page and access the property values in the target page.

Get control information in the target page from controls in the source page.

Built-in Functions - Aggregate Functions

  
Aggregate functions return a single value summarizing a given data set. All aggregate functions are deterministic. NOTE: AVG, SUM, STDEV, STDEVP, VAR and VARP functions cannot operate on BIT data types; they can operate on all other numeric data types.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend