C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Passing only values without parameters for Stored Procedure


Posted Date: 14 Aug 2008    Resource Type: Articles    Category: .NET Framework

Posted By: Anandababu Nagarajan       Member Level: Bronze
Rating:     Points: 10



SqlCommandBuilder.DeriveParameters
----------------------------------

The Code that discovers stored procedure parameters in the background is the SqlCommandBuilder.DeriveParameters method. You call the method passing in an SqlCommand object as such:

SqlCommandBuilder.DeriveParameters(command);

and it will populate the SqlParametersCollection on the command for you. Only thing you need to do is populate the input parameters with their appropriate values and execute the query.

SqlCommandBuilder.DeriveParameters Example


SqlConnection DBConn = New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
DBConn.Open()
'Create command
Dim DBCommand As SqlCommand = DBConn.CreateCommand()
DBCommand.CommandType = CommandType.StoredProcedure

' Stored Procedure Name
DBCommand.CommandText = "StoredProcedureName"
DBCommand.CommandType = CommandType.StoredProcedure

Dim parameterValues As Object() = {Field Values to be added}

' Populate command.Parameters Collection.
' Causes Rountrip to Database.
SqlCommandBuilder.DeriveParameters(DBCommand)
' Initialize Index of parameterValues Array
Dim index As Integer = 0
' Populate the Input Parameters With Values Provided
For Each parameter As SqlParameter In DBCommand.Parameters
If parameter.Direction = ParameterDirection.Input OrElse parameter.Direction = ParameterDirection.InputOutput Then
parameter.Value = parameterValues(index)
index += 1
End If
Next
Dim DBAdapter As New SqlDataAdapter()
Dim DSValue As New DataSet()
DBAdapter.SelectCommand = DBCommand
DBAdapter.Fill(DSValue)
GridVew1.DataSource = DSValue
GridVew1.DataBind()




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
SqlCommandBuilder.DeriveParameters  .  SQL command object  .  Passing Values Without Parameters  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: String Manipulation - Clone and Trim function
Previous Resource: String Manipulaton to find the position of char
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use