Thursday, October 29, 2009

Microsoft Visual Studio 2005 with Microsoft SQL Server 2008 Support

I had an issue connecting to sql server 2008 database
in a VS 2005 application, I used .xsd (datase) to
manipulate data. I got an error,

I hope the fix would be helpfull to you as well, download and
install, Studio 2005 Service Pack 1 Update for Microsoft SQL Server 2008 Support
Thursday, October 22, 2009

How do I get the return value and dataset when calling a stored procedure in a typed DataSet object?

There is no direct way to retrieve the returning value from a stored procedure in typed DataSet object. To accomplish this what you have to do is just add a new method in the partial class of the generated table adapter. Ill show how to do this step by step.

Consider the following stored procedure, which returns a dataset plus a return value. (not a complicated SP). In this case I just return 0 from the SP.

@EmailID VARCHAR (100)
[EmailID] = @EmailID


Now add the method following method in the partial class of the generated table adapter. In my case it's UserTableAdapter.

 partial class UserTableAdapter
public object GetReturnValue(int commandIndex)
return this.CommandCollection[commandIndex].Parameters[0].Value;

Ok, now you can retrieve the return value plus the dataset,

private DSTableAdapters.UserTableAdapter _userAdapter = null;
protected DSTableAdapters.UserTableAdapter Adapter{
if (_userAdapter == null)
_userAdapter = new DSTableAdapters.UserTableAdapter();
return _userAdapter;

This is the method that retrieve dataset and the get return value by calling the method (GetReturnValue(int commandIndex) ) we added in to generated partial class

public int GetUser(string emailid)
int success ;
        DS.UserDataTable userDataTable = Adapter.GetUser(emailid);
if (userDataTable.Rows.Count > 0)
//assingning to variables
FirstName = userDataTable.Rows[0]["FirstName"].ToString();
LastName = userDataTable.Rows[0]["LastName"].ToString();
success = int.Parse(Adapter.GetReturnValue(0).ToString());
catch (Exception ex)
//write you exception handling
    return success; 
Wednesday, October 14, 2009

Limiting Textarea length

I just wrote a java script to limit the max length of a teaxtarea control.
Here is the code snippet.

Limiting Textarea length

<'textarea name="txaDescription" onkeypress="return maxLength(this, 250);" textarea>

and the javascript

function imposeMaxLength(Object, MaxLen)
return (Object.value.length <= MaxLen);

My Achievements

Member of

Blog Archive