MySQL Forums
Forum List  »  MySQL for Visual Studio

System.InvalidOperationException
Posted by: angello rajkumar
Date: August 15, 2015 08:33AM

Hi,

I am getting the error "An unhandled exception of type 'System.InvalidOperationException' occurred in MySql.Data.CF.dll", when I execute my windows application program.

Below is my code.

In app.config:

<connectionStrings>
<add name="ConnectionString" connectionString="server=localhost;database=my_db;user=root;port=3306;password=mypwd;" />
</connectionStrings>

In LoginForms.cs

using System.Configuration;
using MySql.Data.MySqlClient;

namespace MySoftware
{
public partial class Login : Form
{
MySqlConnection conn;
public static int valid = 0;
public Login()
{
InitializeComponent();
}

private void btnLogin_Click(object sender, EventArgs e)
{
var connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
conn = new MySqlConnection(connectionString);
conn.open();
MySqlCommand cmd = new MySqlCommand();
string uname = textBox1.Text; string pwd = textBox2.Text;
cmd.CommandText = "Verify_Login";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@uname", textBox1.Text);
cmd.Parameters["@uname"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@pwd", textBox2.Text);
cmd.Parameters["@pwd"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@result", MySqlDbType.Int32);
cmd.Parameters["@result"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery(); // At this line the error is thrown
int valid = (int)(cmd.Parameters["@result"].Value);
}
}
}

Verify_Login is a stored procedure which is created as below.

CREATE PROCEDURE `Verify_Login`(in uname varchar(20),in pwd varchar(20),out result bool)
BEGIN
select count(*) into result from Login where uname=uname and password=pwd;
END

Could anyone please help me with this?

Options: ReplyQuote


Subject
Views
Written By
Posted
System.InvalidOperationException
2462
August 15, 2015 08:33AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.