0

我试图从我的 c# 应用程序调用一个 mysql 存储过程,该过程有 3 个动态传递的参数,问题既不是错误也不是输出,只是我得到空数据表

 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; 
4

2 回答 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

于 2013-03-21T10:55:33.893 回答
0

试试这个代码

DataTable dt = new DataTable();
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlDataAdapter da =new MySqlDataAdapter(nom_fonction,connection);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add("id", MySqlDbType.Int64).Value = id;
da.Fill(dt);

connection.Close();
于 2019-12-08T23:46:05.270 回答