Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kunal VaishyaRank #990 · 2K reputationPosted Sep 10, 2012, 2:43 AM EDT
//////////////////////// StoredProcedure //////////////
CREATE PROCEDURE StoredProcedure1
@Id As varchar(20),
@Name As Varchar(50) = ''
AS
BEgin
Insert Into Employee
(EId,EName)
Values
(@EId,@EName)
End
RETURN
//////////////////////// .Net Code ////////////////////////////
private void savedata()
{
System.Data.SqlClient.SqlConnection ObjCn = new System.Data.SqlClient.SqlConnection("Connection String");
System.Data.SqlClient.SqlCommand ObjCmd;
ObjCmd = new System.Data.SqlClient.SqlCommand();
ObjCmd.CommandType = CommandType.StoredProcedure;
ObjCmd.CommandText = "StoredProcedure1";
ObjCmd.Connection = ObjCn;
ObjCmd.Parameters.AddWithValue("@EId", "0000000001");
ObjCmd.Parameters.AddWithValue("@EName", "kunal");
ObjCn.Open();
ObjCmd.ExecuteNonQuery();
}
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 10, 2012, 3:15 AM EDT
CREATE PROCEDURE insert1
(@sid varchar(50),@sname varchar(50),@smarks int,@saddress varchar (50),@year varchar(50))
AS
insert student(sid,sname,smarks,saddress,year) values (@sid,@sname,@smarks,@saddress,@year)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Stored_procedure_to_insert._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Stored_procedure_to_insert
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void btn_insert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
com = new SqlCommand("insert1", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@sid", txtid.Text);
com.Parameters.AddWithValue("@sname", txtname.Text);
com.Parameters.AddWithValue("@smarks", int.Parse(txtmarks.Text));
com.Parameters.AddWithValue("@saddress", txtaddress.Text);
com.Parameters.AddWithValue("@year", txtyear.Text);
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
}
}
}
Thanks