DbToDataSet Windows Workflow Activity

Windows Workflow Activity DbToDataSet. Activity C#. Activity , DataSet, DataSet Web Service WCF.
Visual Studio 2010 WCF + WorkFlow, Activity,WorkFlow Windows Form , , DataGridView .
1. Activity DbToDataSet.
Activity InputArguments :
  • ConnectStrig - Northwind.
  • SqlCommand - SQL .
public class InputArguments
{
public string ConnectStrig{ get; set; }
public string SqlCommand{ get; set; }
}
2. Activity DbToDataSet.
Activity OutputResult : dataSet - Error - .
public class OutputResult
{
public string Error{ get; set; }
public DataSet dataSet{ get; set; }
}
3. Activity DbToDataSet.
Activity DbToDataSet , :
  • BeginExecute;
  • EndExecute.
, SQL BeginExecute, Activity EndExecute.
/*20.09.2012. Activity DbToDataSet. 蠠
1. Activity Nortwind DataSet
.
2. InputArguments :
public string ConnectStrig{ get; set; }
public string SqlCommand{ get; set; }

3. OutputResult :
public string Error{ get; set; }
public DataSet dataSet{ get; set; }
4. - .
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Activities;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Windows.Markup;
using System.ComponentModel;
using ClassLibrary;

namespace ActivityLibrary
{
public sealed class DbToDataSet : AsyncCodeActivity<OutputResult>
{
// Input Object
[RequiredArgument]
[DefaultValue(null)]
public InArgument<InputArguments> inputArguments { get; set; }

// Temporary variable for Input Arguments
private InputArguments inputObject= null;
private string connectStr= null;
private string cmdSQL= null;

//Output Object
private OutputResult OutRes = null;

// Temporary use variable
private DataSet dataSet= null;
private SqlConnection connect= null;
private SqlCommand command= null;
private SqlDataAdapter adapter= null;
private SqlDataReader reader= null;

protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
{
try
{
// Input Object
inputObject = inputArguments.Get(context);
// Connection string
connectStr= inputObject.ConnectStrig;
// Command string
cmdSQL= inputObject.SqlCommand;

// If connect string is empty
if (String.IsNullOrEmpty(connectStr)) throw new ArgumentNullException("Value", "Connection String is Empty");

// If command string is empty
if (String.IsNullOrEmpty(cmdSQL)) throw new ArgumentNullException("Value", "Command String is Empty");

connect = new SqlConnection(connectStr);
connect.Open();
command = new SqlCommand(cmdSQL, connect);
adapter = new SqlDataAdapter(command);
context.UserState = adapter;
return adapter.SelectCommand.BeginExecuteReader(callback, state);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}

protected overrideOutputResult EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
{
try
{
SqlDataAdapter adapter = (SqlDataAdapter)context.UserState;
OutRes = new OutputResult();
// End Execute Reader
reader = adapter.SelectCommand.EndExecuteReader(result);
reader.Close();
dataSet = new DataSet();
adapter.Fill(dataSet);
OutRes.dataSet = this.dataSet;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
this.OutRes.Error = ex.ToString();
}
finally
{
this.connect.Close();
}
return OutRes;
}
}
}
4. Activity DbToDataSet.
, , DataGridView.
/* 20.09.2012
Activity DbToDataSet.
1. InputArguments.
2. OutputResult DataSet.
3. DataGridView.
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ClassLibrary;
using System.Diagnostics;

namespace WindowsFormsClient
{
public partial class Form1 : Form
{
private ServiceReference.ServiceClient client;
private ClassLibrary.InputArguments input;
private ClassLibrary.OutputResult output;

public Form1()
{
InitializeComponent();
client= new ServiceReference.ServiceClient();
input= new InputArguments();
output= new OutputResult();
textBox2.Text = @"Data Source=PROGR\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True; Asynchronous Processing=true";
textBox3.Text = @"SELECT Orders.OrderID, Orders.CustomerID, Orders.ShipAddress FROM Orders";
}

private void button1_Click(object sender, EventArgs e)
{
try
{
// Clear DataSource
this.dataGridView1.DataSource = null;
// String for connect
input.ConnectStrig = textBox2.Text;
// SQL command
input.SqlCommand = textBox3.Text;

//Send and receive data
output = client.GetData(input);
// View data
this.dataGridView1.DataSource = output.dataSet.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}

Visual Studio 2010 .
C , .
20.09.2012 .

© Argument Ltd, 2017 ,  : 8-921-215-45-70,   e-mail