your database like
database name :student
table name :tbl_StudentData
Field name :id,name,age,gender,city,phone
Your .aspx page
------------------------------------------------------------------------------------------------
--> Copy following code in your .aspx.cs file
--> if you want to delete record in table or database that time add following namespace in your code behind file
------------------------------------------------------------------------------------------------
--> and then create following object above page load event
------------------------------------------------------------------------------------------------
--> next assign the connection string in page laod event
------------------------------------------------------------------------------------------------
--> and then write following code in your code behind on click event
------------------------------------------------------------------------------------------------
database name :student
table name :tbl_StudentData
Field name :id,name,age,gender,city,phone
Your .aspx page
------------------------------------------------------------------------------------------------
<div>
Enter ID
for delete record :
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox><br/>
<asp:Button ID="Button1"
runat="server"
onclick="Button1_Click"
Text="Delete"
/>
</div>
--> Copy following code in your .aspx.cs file
--> if you want to delete record in table or database that time add following namespace in your code behind file
------------------------------------------------------------------------------------------------
using System.Data;
using System.Data.SqlClient;
--> and then create following object above page load event
------------------------------------------------------------------------------------------------
SqlConnection cn;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
--> next assign the connection string in page laod event
------------------------------------------------------------------------------------------------
cn = new SqlConnection(@"DataSource=\student.mdf;Integrated
Security=True;User Instance=True");
--> and then write following code in your code behind on click event
------------------------------------------------------------------------------------------------
int i = Convert.ToInt32(TextBox1.Text);
cmd =
new SqlCommand("delete from tbl where id='" + i + " '", cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
No comments:
Post a Comment