Click here to Skip to main content
12,070,248 members (29,095 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# ASP.NET , +
Dear All,

I want to use stored procedure in my web based application. It is develop on Visual Studio 2005 and using database Sql Server 2005.
Please also provide C# code to easy understanding.

It is provide for all operation as Create procedure, insertion, Updateion, Deletion and Select result(select query)
Posted 11-Jul-13 1:26am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Smrutiranjan Parida 27-Sep-14 22:10pm
   
This is a nice step by step article.It will help you a lot.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
Bruno Sprecher 27-Sep-14 16:03pm
   
I think your set of links are great. A 5. Regards, Bruno
Maciej Los 29-Sep-14 10:45am
   
Thank you, Bruno ;)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi,

you can try some thing like this


create procedure insert_data
(
    @Id int, @Name Varchar(20) , @address varchar(50)
)
begin
 
Insert into table1(Id,Name,address) values(@Id,@Name,@address)
 
end


you can use the following c# code on button click to insert data

try
  {
     sqlConnection  con = new SqlConnection(dbConnectionString);
     SqlCommand comm= new SqlCommand("insert_data", con);
     comm.CommandType = CommandType.StoredProcedure;
     comm.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text;
     comm.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text;
     comm.Parameters.Add("@Address", SqlDbType.DateTime).Value = txtaddress.Text;
     sqlConnection.Open();
     return comm.ExecuteNonQuery();
     sqlConnection.Close();
  }
catch (SqlException ex)
  {
     Console.WriteLine("SQL Error" + ex.Message.ToString());
     return 0;
  }

I hope it will help you..
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You can try this-
SqlCommand command = new SqlCommand("dbo.sp_name", (SqlConnection)session.Connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@param_name1", "Param Value 1"));
command.Parameters.Add(new SqlParameter("@param_name2", "Param Value 1"));
command.ExecuteNonQuery();
Thanks.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

//this is write in your button event
static SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DbCon"].ConnectionString);

con.open();
SqlCommand cmd = new con.createcommand;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@paramName1", "Param Value 1"));
cmd.Parameters.Add(new SqlParameter("@paramName2", "Param Value 1"));
cmd.ExecuteNonQuery();
con.close();

//create store procedure
CREATE PROCEDURE [dbo].[ProcedureName]
@paramName1 int = 0,
@paramName2 int
AS
SELECT @paramName1, @paramName2
RETURN 0

hope it useful to you...
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 11

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 9

string constr=@"Data Source=Server Name;Initial Catalog=Db name;Integrated Security=true;
SqlConnection con= new SqlConnection(constr);
SqlCommand com = new SqlCommand("StoredProcedureName,constr")
SqlCommandType = commandType.StoredProcedure;
con.Open();
com.Parameters.AddWithValue(@Param,Value);
com.Parameters.AddWithValue(@Param,Value);
com.Parameters.AddWithValue(@Param,Value);
com.ExecuteNonQuary();
con.Close();
  Permalink  
Comments
Wes Aday 4-Oct-14 7:17am
   
The question is over a year old. Already has plenty of answers. Your solution is just a repeat of already posted solutions and does not add anything. Your code is unformatted. Your code will not compile anyway.
victowork 4-Oct-14 7:29am
   
hei man will u neglect the things in ur coding if it was one year old, there are lot more freshers who need these type of ques & ans this is what the site is build for if its annoying to you go to any other where you can have only Fresh things in the world
Wes Aday 4-Oct-14 7:54am
   
Sorry. You are wrong. Does this solution add anything to the solution already here? No it does not. Is the code readable? No it is not. Will the code compile/be useful? No it will not.
If you think that writing childish phrases like "hei", "u", "ques", "ans" makes you sound professional, you are mistaken. Don't think for a minute that you are able to tell me what to do.
CHill60 4-Oct-14 11:31am
   
Shame I can't up vote your comment. Well said anyway
Wes Aday 5-Oct-14 6:54am
   
Thanks. It's the thought that counts. :-)
CHill60 4-Oct-14 11:38am
   
Do you think that "freshers" will be helped by rubbish answers? No. That's why we try to keep the quality of the solutions high.
victowork 7-Oct-14 3:09am
   
What you mean by rubbish ans will you please elaborate? and how it will not compile?
string constr=@"Data Source=Server Name;Initial Catalog=Db name;Integrated Security=true;
SqlConnection con= new SqlConnection(constr);
SqlCommand com = new SqlCommand("StoredProcedureName,constr")
SqlCommandType = commandType.StoredProcedure;
con.Open();
com.Parameters.AddWithValue(@Param,Value);
com.Parameters.AddWithValue(@Param,Value);
com.Parameters.AddWithValue(@Param,Value);
com.ExecuteNonQuary();
con.Close();
CHill60 7-Oct-14 7:28am
   
Try pasting it into Visual Studio. SqlCommandType should be com.CommandType
Value is not defined nor initialised
@Param should be in quotes
Closing quote missing from end of connection string
No such method as ExecuteNonQuary
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

dear friend Stored procedure is very simple concept with secure , you can try this, its a great article
http://dotprogramming.blogspot.com/2014/01/create-stored-procedure-for-accessing.html
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 10

All of Solution are good for Learn.
  Permalink  
Comments
Wes Aday 4-Oct-14 7:15am
   
And how is this a solution to this year old question that already has plenty of answers and does not need any more?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 26 Aug 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100