private void changeNickButton_Click(object sender, EventArgs e) { SqlConnection conn = DBUtils.GetDBConnection(); try { conn.Open(); string command = ("UPDATE [dbo].[user] SET [name]='" + newNickBox.Text + "',dateofchange = '" + DateTime.Today.ToShortTimeString() + "'where [name]='" + nick + "';"); SqlCommand sqlCommand = new SqlCommand(command, conn); sqlCommand.ExecuteNonQuery(); MessageBox.Show("Обновилось"); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } finally { conn.Close(); } }
private void MainForm_Load(object sender, EventArgs e) { nickBox.Text = data; SqlConnection conn = DBUtils.GetDBConnection(); try { conn.Open(); string emailCommand = ("select [email] from [dbo].[User] where [name] ='" + nickBox.Text + "';"); SqlCommand sqlEmailCommand = new SqlCommand(emailCommand, conn); SqlDataReader rdEmail; rdEmail = sqlEmailCommand.ExecuteReader(); while (rdEmail.Read()) { emailBox.Text = rdEmail["email"].ToString(); } rdEmail.Close(); string regDateCommand = ("select [regdate] from [dbo].[User] where [name] ='" + nickBox.Text + "';"); SqlCommand sqlCommand = new SqlCommand(regDateCommand, conn); SqlDataReader rdRegDate; rdRegDate = sqlCommand.ExecuteReader(); while (rdRegDate.Read()) { regDateBox.Text = DateTime.Parse(rdRegDate["regdate"].ToString()).ToShortDateString(); } rdRegDate.Close(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } finally { conn.Close(); } }