Database Reference
In-Depth Information
Figure 13-10. Successful insertion of currency
How It Works
In this program, you use a nonquery to insert the currency into the Sales.Currency table. As you can see
in the Design view of the CommandNonQuery form, we have two TextBox controls and a
DateTimePicker control, so values entered in these controls will be provided to the SQL table via the
SqlCommand object. So, the INSERT query will look like this:
// Insert Query
string sqlIns = "Insert Into Sales.Currency(CurrencyCode,Name,ModifiedDate)" +
"Values(" + "'" + txtCurrencyCode.Text + "','" +
txtName.Text + "','" + dtpModifiedDate.Value.ToString() + "')";
Then you create a command that encapsulates the INSERT query.
// Create command
SqlCommand cmd = new SqlCommand(sqlIns, conn);
// Execute the SQL statements with a call to the following:
cmd.ExecuteNonQuery();
ExecuteNonOuery() executes the INSERT statement, and if executed successfully, it will show
the success message in the lblResultStatus control.
lblInsertStatus.Text = "New Currency Added Successfully!!";
 
Search WWH ::




Custom Search