Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Call a stored procedure from ado.net and pass parameter to it ?

Answer Posted / ashwani

using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;

class MainClass
{
static void Main(string[] args)
{
string SQL = "SELECT * FROM Orders";

string ConnectionString ="Integrated
Security=SSPI;Initial Catalog=Northwind;Data Source=localhost;";
SqlConnection conn = new
SqlConnection(ConnectionString);

SqlCommand StoredProcedureCommand = new
SqlCommand("Sales By Year", conn);
StoredProcedureCommand.CommandType =
CommandType.StoredProcedure;
SqlParameter myParm1 =
StoredProcedureCommand.Parameters.Add( "@Beginning_Date",
SqlDbType.DateTime, 20);
myParm1.Value = "7/1/1996";
SqlParameter myParm2 =
StoredProcedureCommand.Parameters.Add("@Ending_Date",
SqlDbType.DateTime, 20);
myParm2.Value = "7/31/1996";
conn.Open();
SqlDataReader TheReader =
StoredProcedureCommand.ExecuteReader();
string orderlist = "";
while (TheReader.Read())
{
string nextID = TheReader["OrderID"].ToString();
string nextSubtotal = TheReader["Subtotal"].ToString();
orderlist += nextID + '\t' + nextSubtotal + '\n';
}
conn.Close();
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to enable and disable connection pooling?

994


How can we perform transactions in .net?

993


What is ole in vb?

852


What is ole used for?

889


What is ado oledb and odbc?

876


What are all the different methods under sqlcommand?

920


What is sqldatareader?

873


Explain how to call the sql commands asynchronously in ado.net version 2.0?

884


How to creating a SqlCommand Object?

1070


Explain what is datagrid with an example?

1033


Define atomicity?

973


How would you connect to database using .NET?

981


What is ole db and odbc?

859


What is a datareader object?

1045


What is the difference between executenonquery () and executescalar ()?

882