これらは、学生レコードを更新し、SQL バッチベースに学生レコードを挿入するための私の関数です。
public void UpdateStudent(ref student stu, string rollno) //Update the values to corresponding roll number 'rollno'
{
try
{
connection.Open(); //I have already defined the connection and command
command = new SqlCommand("update student set FirstName='"+stu.Firstname+"',LastName='"+stu.Lastname+"',YearOfAdmission="+stu.Yearofadmission+",Branch='"+stu.Branch+"' where RollNo='"+rollno+"'", connection); //Yearofadmission is int
command.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
connection.Close();
}
}
public void insertstudent(ref student s)
{
try
{
connection.Open();
command = new SqlCommand("insert into student values('"+s.Rollno+"','"+ s.Firstname+"','"+s.Lastname+"',"+s.Yearofadmission+",'"+s.Branch+"','"+s.Password+"')", connection);
command.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
connection.Close();
}
}
SQL テーブルに値を挿入する 2 番目の関数「insertstudent」は正しく機能し、値をデータベース テーブルに正しく挿入しています。しかし、最初の関数「生徒の更新」は、データベース テーブルの値を更新していません。エラーも発生していません。それで、私はどこが間違っていますか?
前もって感謝します!