您可以通过以下方式之一完成此任务:
- 使用 MV_To_DataTable() 和 DataTable_To_MV()。您可以创建架构
通过将 Empty DataTable 拖放到 Empty 中的子程序
数据集定义器。
- 通过拖放 Visual Studio Server Explorer 的 U2
进入数据集设计器的子例程。 U2 副程序返回
通过执行诸如 ST=SQLExecDirect(@HSTMT,
"从@TMP SLIST 9 中选择 F1 作为 COL1,F2 作为 COL2,F3 作为 COL3 排序方式
1")
使用 MV_To_DataTable() 和 DataTable_To_MV()
创建 ASP.NET Web 应用程序项目。在项目名称中键入“WebApplication_Subroutine”。
添加对 U2NETDK 程序集 (U2.Data.Client) 的引用
将标题“Welcome to ASP.NET!”更改为“Welcome to U2 Toolkit for .NET Demo on Business Logic Subroutine's multi-value string data to .NET DataSet!”
打开“Default.aspx”文件并进入设计模式。
执行以下操作:
- 拖放按钮控件。将其命名为“加载”
- 拖放按钮控件。将其命名为“更新”
-
拖放 GridView 控件。
右键单击解决方案资源管理器。选择添加 -> 新建项目数据集。在名称框中,键入“Employee.xsd”
将数据表拖放到设计器中。将名称更改为“员工”表。
新建 3 个列(U2 子例程 Schema):
- ID – 数据类型:INT
- 名称 – 数据类型:字符串
- HireDate - 数据类型:日期
在设计模式下打开“Default.aspx”文件。双击“加载按钮”。它将在后面创建事件处理程序代码。
剪切并粘贴以下代码。
protected void Button1_Click(object sender, EventArgs e)
{
U2ConnectionStringBuilder l = new U2ConnectionStringBuilder();
l.Server = "127.0.0.1";
l.UserID = "user";
l.Password = "pass";
l.Database = "HS.SALES";
l.ServerType = "universe";
string lconnstr = l.ToString();
U2Connection c = new U2Connection();
c.ConnectionString = lconnstr;
c.Open();
U2Command command = c.CreateCommand();
command.CommandText = "CALL MV_TO_DATASET_SELECT_SUBROUTINE(?,?)";
command.CommandType = CommandType.StoredProcedure;
U2Parameter p1 = new U2Parameter();
p1.Direction = ParameterDirection.InputOutput;
p1.Value = "";
p1.ParameterName = "@arg_input";
command.Parameters.Add(p1);
U2Parameter p2 = new U2Parameter();
p2.Direction = ParameterDirection.InputOutput;
p2.Value = "";
p2.ParameterName = "@arg_output";
command.Parameters.Add(p2);
command.ExecuteNonQuery();
Employee.EmployeeDataTable dt = new Employee.EmployeeDataTable();
command.Parameters[1].MV_To_DataTable(dt);
Session["GridDataset"] = dt;
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
运行应用程序。按“加载”按钮。
在设计模式下打开“Default.aspx”文件。双击“更新按钮”。它将在页面后面的代码中创建事件处理程序。
剪切并粘贴以下代码。
protected void Button2_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["GridDataset"];
//To TEST, change first row
string s1 = (string)dt.Rows[0]["Name"];
dt.Rows[0]["Name"] = s1 + "NewValue";
// get the modified rows
DataTable dt_changed = dt.GetChanges();
//call DATASET_TO_MV_UPDATE_SUBROUTINE
U2ConnectionStringBuilder l = new U2ConnectionStringBuilder();
l.Server = "127.0.0.1";
l.UserID = "user";
l.Password = "pass";
l.Database = "HS.SALES";
l.ServerType = "universe";
string lconnstr = l.ToString();
U2Connection c = new U2Connection();
c.ConnectionString = lconnstr;
c.Open();
U2Command command = c.CreateCommand();
command.CommandText = "CALL DATASET_TO_MV_UPDATE_SUBROUTINE(?)";
command.CommandType = CommandType.StoredProcedure;
U2Parameter p1 = new U2Parameter();
p1.Value = "";
p1.Direction = ParameterDirection.InputOutput;
p1.ParameterName = "@arg_data";
command.Parameters.Add(p1);
command.Parameters[0].DataTable_To_MV(dt_changed);
// modified data going to subroutine
string lData = (string)command.Parameters[0].Value;
command.ExecuteNonQuery();
}
单击更新按钮时,在调试器中查看修改后的值。
U2 Subrotine 返回结果集/数据集
在 Visual Studio 服务器资源管理器中创建 U2 数据连接。展开存储过程节点。
转到返回结果集/数据集的子程序。将子例程拖放到数据集设计器中。
它显示 INPUT 参数和结果集/数据集列。