从c#调用mysql storageprocedure?

问题描述 投票:0回答:2

im试图从我的c#应用程序中调用mysql存储过程,该过程具有3个参数,它们是动态传递的,问题是没有错误,也没有输出,只是我得到了空的datatable

 MySqlConnection con = new MySqlConnection(myConnectionString);
 con.Open();
 MySqlCommand cmd = new MySqlCommand("User_details", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("username", "aditya");
cmd.Parameters.AddWithValue("password", "123");
cmd.Parameters.AddWithValue("gender", "male");
 MySqlDataAdapter da= new MySqlDataAdapter(cmd);
 DataTable dt = new DataTable();
 da.Fill(dt);
 dataGridView2.DataSource = dt; 
mysql c#-4.0 stored-procedures
2个回答
2
投票

我认为此示例将为您提供帮助>>

protected DataTable RetrieveEmployeeSubInfo(string employeeNo)
            {
                SqlCommand cmd = new SqlCommand();
                SqlDataAdapter da = new SqlDataAdapter();
                DataTable dt = new DataTable();
                try
                {
                    cmd = new SqlCommand("RETRIEVE_EMPLOYEE", pl.ConnOpen());
                    cmd.Parameters.Add(new SqlParameter("@EMPLOYEENO", employeeNo));
                    cmd.CommandType = CommandType.StoredProcedure;
                    da.SelectCommand = cmd;
                    da.Fill(dt);
                    dataGridView1.DataSource = dt;
                }
                catch (Exception x)
                {
                    MessageBox.Show(x.GetBaseException().ToString(), "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    cmd.Dispose();
                    pl.MySQLConn.Close();
                }
                return dt;
            }

或使用相同的信息访问此页面http://www.java2s.com/Code/CSharp/Database-ADO.net/ModifyDataTableinsertdatatodatabasetable.htm


0
投票

尝试此代码

© www.soinside.com 2019 - 2024. All rights reserved.