Hi SUJAYS,
Please refer below sample.
HTML
Id:<br />
<asp:TextBox ID="txtId" runat="server"></asp:TextBox><br />
Name :
<br />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
Country:
<br />
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<asp:Button Text="Update" runat="server" OnClick="Update" />
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
UpdateClass
public class UpdateClass
{
public void Update(string id, string name, string country, string query)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Country", name);
cmd.Parameters.AddWithValue("@CustomerId", id);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
Default.aspx.cs
protected void Update(object sender, EventArgs e)
{
UpdateClass uc = new UpdateClass();
string query = "UPDATE Customers SET Name=@Name, Country=@Country WHERE CustomerId=@CustomerId";
uc.Update(txtId.Text, txtName.Text, txtCountry.Text, query);
}
VB.Net
UpdateClass
Public Class UpdateClass
Public Sub Update(ByVal id As String, ByVal name As String, ByVal country As String, ByVal query As String)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim con As SqlConnection = New SqlConnection(constr)
Dim cmd As SqlCommand = New SqlCommand(query, con)
cmd.Parameters.AddWithValue("@Name", name)
cmd.Parameters.AddWithValue("@Country", name)
cmd.Parameters.AddWithValue("@CustomerId", id)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
End Class
Default.aspx.vb
Protected Sub Update(ByVal sender As Object, ByVal e As EventArgs)
Dim uc As UpdateClass = New UpdateClass()
Dim query As String = "UPDATE Customers SET Name=@Name, Country=@Country WHERE CustomerId=@CustomerId"
uc.Update(txtId.Text, txtName.Text, txtCountry.Text, query)
End Sub