public partial class MainForm : Form
{
// Indicates the a query is being processed
Boolean _processing = false;
TdConnection _cn = null;
String _connectionString = @"Data Source=Teradata1; " +
"Initial Catalog=ProdDB; " +
"Integrated Security=True;Pooling=False ";
public MainForm()
{
InitializeComponent();
}
private void WarehouseCallback(IAsyncResult result)
{
TdCommand command = (TdCommand)result.AsyncState;
try
{
command.EndExecuteNonQuery();
MessageBox.Show("Database has been updated", "Information");
}
catch (TdException t)
{
MessageBox.Show(t.Errors[0].Message, "ERROR");
}
finally
{
_processing = false;
_cn.Close();
}
}
private void buttonSubmit_Click(object sender, EventArgs e)
{
//checking whether the form is already processing
//another query
if (true = _processing)
{
MessageBox.Show(
"Currently updating warehouse information");
}
else
{
String warehouseSQL = "Update ProductWarehouse " +
"set ProdCount = " + textBoxProdCount.Text +
where ProdNo= " + textBoxProdNo.Text;
try
{
_processing = true;
//The application has already created the
//connection object. The name of the object
//is _cn.
TdCommand command = _cn.CreateCommand();
command.CommandText = warehouseSQL;
//setting up the delegate for the asynchronous call
AsyncCallback callback =
new AsyncCallback(WarehouseCallback);
//asynchronous call. The WarehouseCallback callback
//will be invoked by the provider after processing of
//the query has been completed.
command.BeginExecuteNonQuery(callback, command);
}
catch (TdException t)
{
MessageBox.Show(t.Errors[0].Message);
_cn.Close();
}
}
}
}