简体   繁体   中英

How to pass C# datatable to mysql's stored procedure parameter

I have data-table form C# (ASP.NET) side and I want to pass that data table to procedure's parameter in mysql and that hole data table dump to the temporary table in mysql

How can I achieve it in mysql ?

Please let me know !!!!

Thank you,

Here is an example:

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM