Tuesday, 4 September 2012

0 use procedure in asp.net

use procedure in asp.net to save data.
Friends here i am going to tell you how to save data in sql from asp.net using procedure

Step 1:-  First of all you have to create a procedure in sql server  to save data

create proc save-data
(
    @code int, @Empname varchar(50)
)
Insert into tablename (Id, Full-name) values(@code ,@Empname)

Step 2:- Use this code to save data 

try
  {
// Creating sql connection 
 sqlConnection conn = new SqlConnection(enter_your_connectionstring); 
 SqlCommand commandsave= new SqlCommand("save-data", conn);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.Add("@code", SqlDbType.VarChar).Value = txtcode.Text;
     command.Parameters.Add("@empname", SqlDbType.DateTime).Value = txtempname.Text;
     conn.Open();
     return commandsave.ExecuteNonQuery();
     conn.Close();
  }
catch (SqlException expp)
  {
     Console.WriteLine("Error message" + expp.Message.ToString());
    
  }


0 comments:

Post a Comment

 

Coding Authority Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates