我有C#(ASP.NET)端的数据表,我想把这个数据表传递给mysql中的procedure参数,把hole数据表转储到mysql中的临时表
如何在mysql中实现?
请告诉我!!!!
谢谢您,
最佳答案
下面是一个例子:
CREATE TYPE members_table_type AS TABLE
(
mem_username VARCHAR(25),
mem_firstname VARCHAR(25),
mem_lastname VARCHAR(25)
);
CREATE STORED PROCEDURE insert_members
@members members_table_type
AS
BEGIN
INSERT INTO dbo.members
(mem_username, mem_firstname, mem_lastname)
SELECT mem_username, mem_firstname, mem_lastname FROM @members;
END
In .NET:
DataTable members = new DataTable();
members.Columns.Add(new DataColumn("mem_username", typeof(string)));
members.Columns.Add(new DataColumn("mem_firstname", typeof(string)));
members.Columns.Add(new DataColumn("mem_lastname", typeof(string)));
DataRow row = members.NewRow();
row["mem_username"] = "test";
row["mem_firstname"] = "test";
row["mem_lastname"] = "test";
members.Rows.Add(row);
SqlCommand command = new SqlCommand("insert_members");
command.Parameters.Add(members, SqlDbType.Structured);
command.ExecuteNonQuery();
关于c# - 如何将C#数据表传递给mysql的存储过程参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55898038/