私はaspxに次のhtmlを持っているので、それはすでにフォームになっています:-
<asp:TextBox ID="Name" runat="server" MaxLength="50" Width="175px"></asp:TextBox>
私はボタンを持っています:-
<asp:Button ID="updateDetails" Text="Update Details" runat="server" OnClick="updateDetails_Click" />
背後にあるコードには、updateDetails_Click
procがあります:-
protected void updateDetails_Click(object sender, EventArgs e)
{
utils utils = new utils();
string connectionString = ConfigurationManager.ConnectionStrings[utils.liveTest() + "arenadestinationsConnectionString"].ToString();
string SQL = "UPDATE Users SET "
+ "Name = @Name, "
+ "WHERE IdUser = @iDUser";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(SQL, connection);
command.Parameters.AddWithValue("@Name", Name.Text);
command.Parameters.AddWithValue("@iDUser", Session["loggedIn"].ToString());
try
{
connection.Open();
command.ExecuteReader();
}
catch
{
}
finally
{
connection.Close();
}
}
}
[名前]テキストボックスに新しいテキストを入力した場合、[詳細の更新]ボタンをクリックすると、Name.Textには常に元のテキストが表示され、変更されたテキストは表示されません。
私は何が間違っているのですか?私は自分自身をVBからC#に変換しているので、学ぶべきいくつかのトリックがあることは間違いありません。