ASP.NET DataGridView Update
Sir, I want your help in Update function in ASP.NET.
I providing you my code in order.
1)SQL Stored Procedure:-
ALTER PROCEDURE classEdit
@classId numeric(18,0),
@className varchar(20),
@noOfSeats int
AS
if NOT EXISTS (SELECT className FROM tbl_Class WHERE className=@className)
BEGIN
UPDATE tbl_Class
SET
className=@className,
noOfSeats=@noOfSeats
WHERE classId=@classId
END
ELSE if EXISTS (SELECT className FROM tbl_Class WHERE classId=@classId AND className=@className)
BEGIN
UPDATE tbl_Class
SET
noOfSeats=@noOfSeats
WHERE classId=@classId
END
ELSE
BEGIN
return -1
END
2) classInfo.cs:-
public class classInfo
{
public decimal classId
{
get;
set;
}
public string className
{
get;
set;
}
public int noOfSeats
{
get;
set;
}
}
3) ClassSP.cs:-
public void classEdit(classInfo infoClass)
{
try
{
if (sqlCon.State == ConnectionState.Closed)
{
sqlCon.Open();
}
SqlCommand sqlCmd = new SqlCommand("classEdit", sqlCon);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add("@classId", SqlDbType.Decimal).Value = infoClass.classId;
sqlCmd.Parameters.Add("@className", SqlDbType.NVarChar).Value = infoClass.className;
sqlCmd.Parameters.Add("@noOfseats", SqlDbType.Int).Value = infoClass.noOfSeats;
int incount = sqlCmd.ExecuteNonQuery();
if (incount > 0)
{
HttpContext.Current.Response.Write("<script>alert('Updated Successfully');</script>");
}
}
catch (Exception )
{
throw;
}
finally
{
sqlCon.Close();
}
}
I want your help from here.
I sets btnSave.Text="Update" when press edit link button in gridview
please send me the btn_Click function to update