Use for this KeyDown
event
private void YourTextBox_KeyDown(object sender, KeyEventArgs e)
{
String connection= "Data Source=YourServer;Initial Catalog=YourDatabase;user=User;password=YourPassword;Integrated Security=True;";
if (e.KeyCode == Keys.Enter)
{
string insertCmdText = "INSERT INTO table(column1)values(@valueForColumn1)";
SqlCommand sqlCom = new SqlCommand(insertCmdText,connection);
sqlCom.Paramaters.AddWithValue("@valueForColumn1",YourTextBox.Text);
connection.Open();
sqlCom.ExecuteNonQuery();
connection.Close();
}
}
But consider that saving into Database after KeyPress event is not a right way to go.
For your future questions please provide your code.
2
solved Entering value to database after pressing enter from a textbox [closed]