Anvar S

Anvar S

  • NA
  • 12
  • 1.3k

grid view and stored procedure

Aug 9 2018 5:39 AM
hai this is all i done using stored procedure insert,update and delete.i also select a gridview in visual studio form.Now i want to display the inserted datas on the grid view using stored procedure.
what would be the likely code for it. 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication31
{
public partial class insertion : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=REDEEMER3\\REDEEMER;Initial Catalog=Test;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("new",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id",0);
cmd.Parameters.AddWithValue("@name", txtname.Text);
cmd.Parameters.AddWithValue("@email", txtemail.Text);
cmd.Parameters.AddWithValue("@address", txtaddress.Text);
cmd.Parameters.AddWithValue("@password", txtpwd.Text);
cmd.Parameters.AddWithValue("@query", 1);
cmd.ExecuteNonQuery();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("new", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("query", 2);
cmd.Parameters.AddWithValue("id", 0);
cmd.Parameters.AddWithValue("name", txtname.Text);
cmd.Parameters.AddWithValue("@email", txtemail.Text);
cmd.Parameters.AddWithValue("@address", txtaddress.Text);
cmd.Parameters.AddWithValue("@password", txtpwd.Text);
cmd.ExecuteNonQuery();
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("new", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@query", "3");
cmd.Parameters.AddWithValue("@id", txtid.Text);
cmd.Parameters.AddWithValue("@name", 0);
cmd.Parameters.AddWithValue("@email", 0);
cmd.Parameters.AddWithValue("@address", 0);
cmd.Parameters.AddWithValue("@password", 0);
cmd.ExecuteNonQuery();
}
}
}

Answers (1)