Database Reference
In-Depth Information
database = AdventureWorks");
// Select query
string sqlSelect = @"select CurrencyCode
from Sales.Currency";
SqlCommand cmd = new SqlCommand(sqlSelect, conn);
try
{
// Open connection
conn.Open();
// Execute query via ExecuteReader
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
lstCurrency.Items.Add(rdr[0]);
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message + ex.StackTrace, "Exception Details");
}
finally
{
conn.Close();
}
}
10. Now it's time to add functionality for the Delete Currency button. Double-click
the Delete Currency button, and it will open the code editior window, showing
the btndeleteCurrency_Click event. Modify the btnDeleteCurrency_Click
event to look like Listing 13-6.
Listing 13-6. CommandStoredProcedure.cs
private void btnDeleteCurrency_Click(object sender, EventArgs e)
{
// Create connection
SqlConnection conn = new SqlConnection(@"server = .\sql2012;
integrated security = true;
database = AdventureWorks");
// Create command object with Stored Procedure name
SqlCommand cmd = new SqlCommand("sp_DeleteCurrency", conn);
//Set command object for Stored Procedure execution
cmd.CommandType = CommandType.StoredProcedure;
Search WWH ::




Custom Search