How to access stored procedure
-
I have created stored procedure for calculating salary.how will i access that procedure using c#.NET
vinoth
-
I have created stored procedure for calculating salary.how will i access that procedure using c#.NET
vinoth
-
I have created stored procedure for calculating salary.how will i access that procedure using c#.NET
vinoth
Look at that, it can give you an idea ) conn = new SqlConnection("Server=(local);DataBase=Northwind;Integrated Security=SSPI"); conn.Open(); // 1. create a command object identifying // the stored procedure SqlCommand cmd = new SqlCommand( "CustOrderHist", conn); // 2. set the command object so it knows // to execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; // 3. add parameter to command, which // will be passed to the stored procedure cmd.Parameters.Add( new SqlParameter("@CustomerID", custId));
thanks for everything i have...
-
I have created stored procedure for calculating salary.how will i access that procedure using c#.NET
vinoth
if you are using SQL then you need 1. import the system.data.sqlclient namespace 2. then create a object of sqlconnection with appropriate parameters 3. then either create a objects of sqlcommand and sqldatareader and in commad specify the storedprocedure name or you can also create a object of sqldataadaptar and sqldataset and in sqldataadaptar you can set your stored procedure name. if u r working on anyother db than import the namespace and create objects accordingly
-
I have created stored procedure for calculating salary.how will i access that procedure using c#.NET
vinoth
Hi, Visit http://support.microsoft.com/kb/310070[^] Try to learn to use google for such queries
-
I have created stored procedure for calculating salary.how will i access that procedure using c#.NET
vinoth
if you r using SQL please check the below code string strSqlConnectionstring = "sqlserver details with provider"; System.Data.SqlClient.SqlConnection _ObjSQLCon = new System.Data.SqlClient.SqlConnection(strSqlConnectionstring.ToString()); System.Data.SqlClient.SqlCommand _ObjSqlCom = new System.Data.SqlClient.SqlCommand(); try { _ObjSQLCon.Open(); _ObjSqlCom.Connection = _ObjSQLCon; // your store procedure name _ObjSqlCom.CommandText = "Your Store procedure name"; _ObjSqlCom.CommandType = System.Data.CommandType.StoredProcedure; // you can add parameter as per your requirement // parameter name & datatype should be as per you have mentioned in your procedure // set the direction of your parameter // you need to add output parameter in the same way but direction out be output _ObjSqlCom.Parameters.Add("your parameter name", System.Data.SqlDbType.Char, 50).Direction = System.Data.ParameterDirection.Input; _ObjSqlCom.Parameters.Add("your output parameter name", System.Data.SqlDbType.Char, 50).Direction = System.Data.ParameterDirection.Output; _ObjSqlCom.Parameters[0].Value = "your parameter value"; _ObjSqlCom.ExecuteNonQuery(); // to get the output value you can use either array location of that parameter or the parameter name // if you are confused then just right click on _ObjSqlCom and view it in immediate window after you have executed _ObjSqlCom.ExecuteNonQuery(); } catch { } finally { strSqlConnectionstring = string.Empty; if (_ObjSqlCom != null) { _ObjSqlCom.Dispose(); _ObjSqlCom = null; } if (_ObjSQLCon != null) { if (_ObjSQLCon.State != System.Data.ConnectionState.Closed) { _ObjSQLCon.Close(); } _ObjSQLCon.Dispose(); _ObjSQLCon = null; } } if you further douts feel free to email me at ashwin@omtechsolutions.com :)
Ashwin Shetty. Mumbai. India