如何从ASP.NET使用多个输入值调用MySQL存储过程 [英] How to call MySQL stored procedure with multiple input values from ASP.NET

查看:45
本文介绍了如何从ASP.NET使用多个输入值调用MySQL存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的MySQL存储过程.

This is my MySQL stored procedure.

    create procedure InsertIntotblStudentProc (PStudentId VARCHAR(10), PStudentName VARCHAR(10))
    begin
    insert into tblStudent (StudentId, StudentName) values (PStudentId, PStudentName);
end;

这是我的ASP代码.

   `MySqlCommand cmd = new MySqlCommand("InsertIntotblStudent", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("PStudentId", TextBox1.Text);`

我在这里停了下来,因为我想用两个参数调用过程,而我的另一个参数在TextBox2中.

I stopped here as I want to call procedure with two parameters and my other parameter is in TextBox2.

帮我提建议.

推荐答案

您可以在command.Parameters中添加多个参数.有关相同内容,请参见下面的代码.

You can add mutiple parameters in command.Parameters, refer the below code for the same.

        var connectionString = ""; // Provide connecction string here.
    using (var connection = new MySqlConnection(connectionString))
    {
        MySqlCommand command = new MySqlCommand("InsertIntotblStudent", connection);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add(new MySqlParameter("PStudentId", TextBox1.Text));
        command.Parameters.Add(new MySqlParameter("PStudentName", TextBox2.Text));
        command.Connection.Open();
        var result = command.ExecuteNonQuery();
        command.Connection.Close();
    }

这篇关于如何从ASP.NET使用多个输入值调用MySQL存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆