MSSQL サーバーのテーブルから一連の行を選択するフォームがあります。現在、このフォームはデータの更新に使用されていますが、フォームを使用してデータを更新した後、正しく行われますが、次のページにリダイレクトされます。そのテーブル内のすべての行のデータグリッドであり、別の行を選択して更新することができます。もう一度更新した行を選択すると、「ユーザー 'slehan_ticketadmin' のログインに失敗しました」というメッセージが表示されます。
データを更新するために 1 分前にフォームを使用したため、ユーザー名とパスワードが正しいことがわかりました。ホストが制限しているため、SQL エラー ログを表示できませんが、更新フォームのコード ビハインドを次に示します。
namespace YakStudios_Support.ys_admin
{
public partial class UpdateTicket : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int ticketID = Convert.ToInt32(Request.QueryString["ticketID"]); // Grabs the ?ticketid number from the URL
Ticket ticketBeingUpdated = TicketDatabase.selectTicketFromDatabase(sqlErrorLabel, ticketID); // Creates a new Ticket object to be used by the form to populate the text boxes
/* Form Field Population */
// Email
emailTxt.Text = ticketBeingUpdated.getEmail();
// Date Submitted
dateSubText.Text = ticketBeingUpdated.getDateSubmitted().ToString();
// Ticket Class
classDropDown.SelectedValue = ticketBeingUpdated.getTicketClass();
// Ticket Status
statusDrop.SelectedValue = ticketBeingUpdated.getStatus();
// Subject
subjectTxt.Text = ticketBeingUpdated.getSubject();
// Text
textTxt.Text = ticketBeingUpdated.getTicketContent();
}
}
protected void editBtn_Click(object sender, EventArgs e)
{
emailTxt.Enabled = true;
dateSubText.Enabled = true;
classDropDown.Enabled = true;
statusDrop.Enabled = true;
subjectTxt.Enabled = true;
textTxt.Enabled = true;
}
protected void submitBtn_Click(object sender, EventArgs e)
{
int ticketID = Convert.ToInt32(Request.QueryString["ticketID"]); // Grabs the ?ticketid number from the URL
DateTime convertedDate = Convert.ToDateTime(dateSubText.Text);
Ticket ticketUpdated = new Ticket(emailTxt.Text, convertedDate, subjectTxt.Text, textTxt.Text, statusDrop.SelectedValue, classDropDown.SelectedValue);
TicketDatabase.updateTicketInDatabase(ticketUpdated, sqlErrorLabel, ticketID);
Response.Redirect("ticketqueue.aspx");
}
}
}
ご覧の Ticket クラスは、SQL Server から更新/選択/削除されたチケットのデータを保持する単なるクラスです。構造化された方法でデータを変更/保持するための簡単な方法です。次の行に注意を向けたいと思います。
Ticket ticketBeingUpdated = TicketDatabase.selectTicketFromDatabase(sqlErrorLabel, ticketID);
データベースからチケットを挿入/選択/更新/削除する一連のメソッドを持つ TicketDatabase という別のクラスがあります。selectTicketFromDatabase() メソッドのスタブを次に示します。
public static Ticket selectTicketFromDatabase(Label sqlErrorLabel, int ticketID)
{
SqlCommand sqlCmd = new SqlCommand("SELECT * from yak_tickets");
using (SqlConnection selSqlConn = new SqlConnection(sqlConn.ConnectionString))
//using (sqlConn)
{
sqlCmd.Connection = selSqlConn;
selSqlConn.Open(); // Open the SQL connection
//sqlCmd.Connection = sqlConn;
//sqlConn.Open(); // Open the SQL Connection
SqlDataReader reader = sqlCmd.ExecuteReader();
Ticket ticketReturning = null; // Initializes the ticketReturning but it's not allocated
// Call during reading
while (reader.Read())
{
/* Objects to hold values from reader */
string emailString = reader["email"].ToString();
DateTime dateSubbed = Convert.ToDateTime(reader["dateSubmitted"].ToString());
string subjectString = reader["subject"].ToString();
string textString = reader["ticketText"].ToString();
string statusString = reader["statusid"].ToString();
string classString = reader["ticketClass"].ToString();
ticketReturning = new Ticket(emailString, dateSubbed, subjectString, textString, statusString, classString);
}
selSqlConn.Close();
return ticketReturning;
}
}
これをローカルホストサーバーでテストして、サーバーまたはコードがエラーの原因であるかどうかを確認しますが、この特定の問題に対する提案/サポートは引き続き受け付けています。
前もって感謝します!