Hi Friends.......
I have a database in sql server .I want insert the new data in data base with stored procedure from .NET front end. How to do ,Please explain with an example ?
Thanks.....
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 12, 2011, 1:14 PM
CREATE PROCEDURE display
AS
select * from student
SqlConnection con=new SqlConnection("workstation id=\"HOME-Z8CKE1NER2\";packet size=4096;user id=sa;initial catalog=pint" +
"u;persist security info=False");
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
private void btnload_Click(object sender, System.EventArgs e)
{
con.Open();
com = new SqlCommand("display", con);
com.CommandType = CommandType.StoredProcedure;
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");
Gridview1.DataSource = ds;
Gridview1.DataMember = "student";
Gridview1.Databind();
con.Close();
}
Thanks
Vineet Kumar SainiPosted Dec 13, 2011, 6:20 PM
Vineet Kumar SainiPosted Dec 12, 2011, 1:03 PM
Hi Nayak Ji. If we want to show whole table in grid view using stored procedure, How to do ,Please explain an example ?
Satyapriya NayakPosted Dec 12, 2011, 12:11 PM
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)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class Form1 : System.Windows.Forms.Form
{
SqlConnection con=new SqlConnection("workstation id=\"HOME-Z8CKE1NER2\";packet size=4096;user id=sa;initial catalog=pint" +
"u;persist security info=False");
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds=new DataSet();
private void btninsert_Click(object sender, System.EventArgs e)
{
con.Open();
com = new SqlCommand("insert1", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@sid", txtid.Text);
com.Parameters.Add("@sname", txtname.Text);
com.Parameters.Add("@smarks",int.Parse (txtmarks.Text));
com.Parameters.Add("@saddress", txtaddress.Text);
com.Parameters.Add("@year", txtyear.Text);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("record added");
}
}
Thanks