C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Input Outparameter in Sqlserver


Posted Date: 11 Jun 2007      Posted By: tusar biswal      Member Level: Silver     Points: 2   Responses: 2



How to write a sp in sqlserver for input and output parameter and execute it in asp.net. ex I want to input a empid and name and it will return the corresponding designation from the table. How to write sps and execute it in a asp.net file




Responses

Author: sathiyasivam    11 Jun 2007Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

C the below code this may help you ..Still any query reply me



Private Sub btnGetAuthors_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGetAuthors.Click
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

'Create a connection to the SQL Server.
MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes")

'Create a DataAdapter, and then provide the name of the stored procedure.
MyDataAdapter = New SqlDataAdapter("GetAuthorsByLastName", MyConnection)

'Set the command type as StoredProcedure.
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

'Create and add a parameter to Parameters collection for the stored procedure.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@au_lname", _
SqlDbType.VarChar, 40))

'Assign the search value to the parameter.
MyDataAdapter.SelectCommand.Parameters("@au_lname").Value = Trim(txtLastName.Text)

'Create and add an output parameter to Parameters collection.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@RowCount", _
SqlDbType.Int, 4))

'Set the direction for the parameter. This parameter returns the Rows returned.
MyDataAdapter.SelectCommand.Parameters("@RowCount").Direction = ParameterDirection.Output

DS = New DataSet() 'Create a new DataSet to hold the records.
MyDataAdapter.Fill(DS, "AuthorsByLastName") 'Fill the DataSet with the rows returned.

'Get the number of rows returned, and then assign it to the Label control.
'lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " Rows Found!"
lblRowCount.Text = MyDataAdapter.SelectCommand.Parameters(1).Value & " Rows Found!"

'Set the data source for the DataGrid as the DataSet that holds the rows.
Grdauthors.DataSource = DS.Tables("AuthorsByLastName").DefaultView

'Bind the DataSet to the DataGrid.
'NOTE: If you do not call this method, the DataGrid is not displayed!
Grdauthors.DataBind()

MyDataAdapter.Dispose() 'Dispose of the DataAdapter.
MyConnection.Close() 'Close the connection.
End Sub





Author: ChandraShekar Thota    11 Jun 2007Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

i accept with sataya sivam

chandrashekarthota@gmail.com /92 93 95 95 39
FREE SESSIONS ON .NET AND VISUALSTUDIO



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : plzzzzzzzz help me
Previous : Query
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use