| Name | |
| Age | |
==================================
student.aspx.cs
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;
using System.Configuration;
namespace class_01
{
public partial class student : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
Fill_grid();
}
public void Fill_grid()
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from student",con);
SqlDataAdapter da =new SqlDataAdapter(cmd);
DataTable dt =new DataTable();
da.Fill(dt);
grd.DataSource=dt;
grd.DataBind();
con.Close();
}
protected void savebtn_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into student(Name,Age) values('" + txtname.Text + "','" + txtage.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
Fill_grid();
}
protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DHOOM3")
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from student", con);
cmd.Parameters.AddWithValue("@id", e.CommandArgument);
cmd.ExecuteNonQuery();
con.Close();
Fill_grid();
}
else if (e.CommandName == "KRISS3")
{
con.Open();
SqlCommand cmd = new SqlCommand(", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", e.CommandArgument);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
txtname.Text = dt.Rows[0][1].ToString();
txtage.Text = dt.Rows[0][3].ToString();
}
}
}
}
============================Web.config
Rafnas T PPosted May 5, 2017, 2:02 AM
Karthi KeyanPosted May 5, 2017, 1:57 AM
Nigel FernandesPosted May 5, 2017, 12:48 AM
Rafnas T PPosted May 5, 2017, 12:44 AM
Nigel FernandesPosted May 5, 2017, 12:39 AM
Manav PandyaPosted May 5, 2017, 12:39 AM
Raja TPosted May 5, 2017, 12:18 AM
Amit GuptaPosted May 4, 2017, 2:45 PM