Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am making a program (windows application) and i need to conect it to mysql database and make a report but a cant make it to connect the database with crystal report with a dataset any idea??

C#
public partial class Form2 : Form { 
private TableLogOnInfo infoEntrada = new TableLogOnInfo(); 
public Form2() { InitializeComponent(); 
} 
private void Form2_Load(object sender, EventArgs e) { confInfoEntrada(); 
CrystalReport1 listaReportes = new CrystalReport1(); 
ReportDocument docReporte = new ReportDocument(); 
MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();
connBuilder.Add("DataBase", "DataBase");
connBuilder.Add("Data Source", "ipwithdatabasemysql");
connBuilder.Add("User Id", "user");
connBuilder.Add("Password", "pwd"); 
MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString); 
docReporte.Load(@"C:\addresstowhere its located\CrystalReport1.rpt"); 
DataTable tablaDatos = new DataTable(); 
try { 
string cadComando = " "; 
cadComando = "SELECT * FROM table"; connection.Open(); 
MySqlDataAdapter adapDatos = new MySqlDataAdapter(cadComando, connection); 
tablaDatos.Clear(); 
adapDatos.Fill(tablaDatos); 
} 
catch (Exception ex) 
{ MessageBox.Show(ex.Message); 
} 
finally { 
connection.Close(); 
} 
listaReportes.Database.Tables[0].SetDataSource(tablaDatos);
crystalReportViewer1.ReportSource = docReporte; crystalReportViewer1.Zoom(1); 
} private void confInfoEntrada() { 
try { 
infoEntrada.ConnectionInfo.ServerName = "ipwithserver"; 
infoEntrada.ConnectionInfo.UserID = "User"; 
infoEntrada.ConnectionInfo.Password = "pwd"; 
infoEntrada.ConnectionInfo.DatabaseName = "database"; 
} catch (Exception ex) { 
MessageBox.Show(ex.Message); 
} 
} 
} 
} 
Posted
Updated 21-Nov-12 3:22am
v2
Comments
Kschuler 20-Nov-12 17:06pm    
What did you try and what error message did you get?
azteca_04 20-Nov-12 17:39pm    
Hi,

i dont get any errors the report just appears blank with no information
joshrduncan2012 20-Nov-12 17:26pm    
Please show code with existing attempt.
azteca_04 20-Nov-12 17:38pm    
<pre>public partial class Form2 : Form
{
private TableLogOnInfo infoEntrada = new TableLogOnInfo();

public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
confInfoEntrada();
CrystalReport1 listaReportes = new CrystalReport1();
ReportDocument docReporte = new ReportDocument();
MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

connBuilder.Add("DataBase", "DataBase");
connBuilder.Add("Data Source", "ipwithdatabasemysql");
connBuilder.Add("User Id", "user");
connBuilder.Add("Password", "pwd");

MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);

docReporte.Load(@"C:\addresstowhere its located\CrystalReport1.rpt");

DataTable tablaDatos = new DataTable();

try
{
string cadComando = " ";
cadComando = "SELECT * FROM table";
connection.Open();
MySqlDataAdapter adapDatos = new MySqlDataAdapter(cadComando, connection);
tablaDatos.Clear();
adapDatos.Fill(tablaDatos);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
listaReportes.Database.Tables[0].SetDataSource(tablaDatos);
crystalReportViewer1.ReportSource = docReporte;
crystalReportViewer1.Zoom(1);
}


private void confInfoEntrada()
{
try
{
infoEntrada.ConnectionInfo.ServerName = "ipwithserver";
infoEntrada.ConnectionInfo.UserID = "User";
infoEntrada.ConnectionInfo.Password = "pwd";
infoEntrada.ConnectionInfo.DatabaseName = "database";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
</pre>
Kschuler 21-Nov-12 9:23am    
Next time, please click the Improve Question button and add this code to your original question.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900