anand kulkarni

anand kulkarni

  • NA
  • 99
  • 48.7k

Connect to mysql and excuting crystal report

Oct 26 2014 8:31 AM

I am trying to execute the crystal report with below code but I dont know what is going wrong .

Here is my connection class to mysql 

-------------------------------------------------------------------------------------

namespace schoolbell
{
class con_db
{
private static string Database = "scbell";
private static string Server = "localhost";
private static string Password = "";
private static string Username = "";

private static string constring = "Server=" + Server + ";" + "Database=" + Database + ";" + "Uid=" + Username + ";" + "Password=" + Password + ";";
public static MySqlConnection con = new MySqlConnection(constring);

public con_db()
{

}

}
}



========================


try

{
Cursor = Cursors.WaitCursor;
timer1.Enabled = true;
CrystalReport3 rpt = new CrystalReport3();
MySqlCommand con = new MySqlCommand();
MySqlDataAdapter myda = new MySqlDataAdapter();
DataSet myds = new DataSet();
con = new MySqlConnection(con_db.con);


// Here I have error 

con.Connection = MySqlCommand(con_db.con);

// 

con.CommandText = " select *from feest ";
con.CommandType = CommandType.Text;
myda.SelectCommand = con;
myda.Fill(myds,"feest");
rpt.SetDataSource(myds);
feestru fm = new feestru();
fm.crystalReportViewer1.ReportSource = rpt;
fm.Visible = true;

}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);

}

}

Regards 

anand 



Answers (8)