StudentUpdatePage.aspx.cs
Dosyayı İndir
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
namespace WebProject
{
public partial class StudentUpdatePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
string connectionString = "server=localhost;DataBase=CourseDatabase;uid=sa;pwd=godoro";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
string studentIdString = Request["StudentId"];
String sql = "select * from Student where StudentId=" + studentIdString;
SqlCommand command = new SqlCommand(sql, connection);
SqlDataReader reader = command.ExecuteReader();
if (reader.Read()) {
int studentId = (int)reader["StudentId"];
string firstName = (string)reader["FirstName"];
string lastName = (string)reader["LastName"];
StudentIdLabel.Text = studentId.ToString();
FirstNameTextBox.Text = firstName;
LastNameTextBox.Text = lastName;
} else {
MessageLabel.Text = "Öğrenci bulunamadı : " + studentIdString;
}
reader.Close();
connection.Close();
}
}
protected void OkButton_Click(object sender, EventArgs e)
{
string studentIdString = StudentIdLabel.Text;
string firstName = FirstNameTextBox.Text;
string lastName = LastNameTextBox.Text;
string connectionString = "server=localhost;DataBase=CourseDatabase;uid=sa;pwd=godoro";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
string sql = "update Student set FirstName='" + firstName + "',LastName='" + lastName + "' where StudentId=" + studentIdString + "";
SqlCommand command = new SqlCommand(sql, connection);
int affectedRowCount = command.ExecuteNonQuery();
if (affectedRowCount >= 0) {
MessageLabel.Text = "Öğrenci başarıyla güncellenmiştir";
} else {
MessageLabel.Text = "Öğrenci güncellerken hata oluştu";
}
connection.Close();
}
protected void CancelButton_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
}
}
Dosyayı İndir