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 » .NET »

how can i use storedprocedure in dotnet


Posted Date: 04 Sep 2008      Posted By: kiran      Member Level: Silver     Points: 1   Responses: 2



dear friend...

think i have stored procudure spAdd which has 2 parameter name,address.
i need to access in asp.net.(connection am getting from web.config file)
please tell me the code with standard format for both using datareader,and dataset.

thanks in advance

kiran





Responses

Author: Praveen    04 Sep 2008Member Level: DiamondRating: 3 out of 53 out of 53 out of 5     Points: 3

SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter name;
name = da.SelectCommand.Parameters.Add("@name", SqlDbType.VarChar, 50);
name.Value = txtName.Text;
SqlParameter address;
address = da.SelectCommand.Parameters.Add("@address", SqlDbType.VarChar, 100);
address.Value = txtAdress.Text;
da.SelectCommand.Connection = con;
da.SelectCommand.CommandText = "sp_getAdress";
DataSet ds = new DataSet();
da.Fill(ds)



Author: Bunty    04 Sep 2008Member Level: DiamondRating: 3 out of 53 out of 53 out of 5     Points: 3

Hi,

This code sample shows how to call a stored procedure which returns a value from VB.NET.


Create procedure prc_getBal(@cid int,@bal money output)
As
Begin
Select @bal=bal from customers
where cid=@cid
End


Code in VB.NET


Imports System.Data.SQLClient

public Class Form
Dim con as SQLConnection
Dim cmd as SQLCommand


Under FindBalance Button:


Dim cid as integer=InputBox("Enter Cid")
con=new SQLConnection("user id=sa;password=123;database=")
cmd=new SQLCommand("prc_getBal")
cmd.CommandType=CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@cid",cid)
cmd.Parameters.AddWithValue("@bal",SQLDbType.Money).Direction=ParameterDirection.Output
con.open()
cmd.ExecuteNonQuery()
MessageBox.Show(cmd.Parameters("@bal").Value)
con.Close()

Thanks and Regards
S.S.Bajoria


Thanks & Regards
S.S.Bajoria



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 : how can i create assempbly?
Previous : diff between usercontrol and custom control
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use