调用mysql的存储过程从c#? [英] calling mysql storedprocedure from c#?

查看:284
本文介绍了调用mysql的存储过程从c#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  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;


解决方案

我认为这个例子会帮助你

  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 。错误);
}
finally
{
cmd.Dispose();
pl.MySQLConn.Close();
}
return dt;
}

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


im trying to call a mysql stored procedure from my c# application , the procedure has 3 parameters which im passing dynamically, the problem is im not error nor the output, just im getting empty 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; 

解决方案

I think this example will help you

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

or visit this page with the same information http://www.java2s.com/Code/CSharp/Database-ADO.net/ModifyDataTableinsertdatatodatabasetable.htm

这篇关于调用mysql的存储过程从c#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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