Update data C#

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.1 kB
7
Indexable
Never
private async Task SaveEdit()
        {
            //Save student

            Sqlcmd.Parameters.Clear();
            await Conopen();
            Strsql =
                "Update tbl_students set F_name=@F_name," +
                "L_name=@L_name, B_Date=@B_Date, Address=@Address," +
                "S_mobile_number=@S_mobile_number, gender=@gender Where LRN=@LRN";
            Sqlcmd.Parameters.AddWithValue("@F_name", txtfname.Text);
            Sqlcmd.Parameters.AddWithValue("@L_name", txtlname.Text);
            Sqlcmd.Parameters.AddWithValue("@B_Date", pickerbdate.Text);
            Sqlcmd.Parameters.AddWithValue("@Address", txtaddress.Text);
            Sqlcmd.Parameters.AddWithValue("@S_mobile_number", txtstudentmobile.Text);
            Sqlcmd.Parameters.AddWithValue("@gender", cbogender.Text);
            Sqlcmd.Parameters.AddWithValue("@LRN", SelectedStudentId);
            Sqlcmd.Connection = Cnn;
            Sqlcmd.CommandText = Strsql;
            Sqlcmd.ExecuteNonQuery();
            Sqlcmd.Dispose();
            Strsql = "";
            //Save guardian

            Sqlcmd.Parameters.Clear();
            Strsql =
                "Update tbl_guardian set guardian_name=@guardian_name," +
                "guardian_address=@guardian_address, guardian_relationship=@guardian_relationship," +
                "guardian_mobile=@guardian_mobile Where guardian_id=@guardian_id";
            Sqlcmd.Parameters.AddWithValue("@guardian_name", txtguardianname.Text);
            Sqlcmd.Parameters.AddWithValue("@guardian_address", txtguardianaddress.Text);
            Sqlcmd.Parameters.AddWithValue("@guardian_relationship", txtrelationship.Text);
            Sqlcmd.Parameters.AddWithValue("@guardian_mobile", txtguardianmobile.Text);
            Sqlcmd.Parameters.AddWithValue("@guardian_id", guardianId);
            Sqlcmd.Connection = Cnn;
            Sqlcmd.CommandText = Strsql;
            Sqlcmd.ExecuteNonQuery();
            Sqlcmd.Dispose();
            Strsql = "";
            Cnn.Close();
            saved = true;
            Close();

            
        }