2011-08-05 45 views
6

Tôi mới dùng Visual Studio 2010 C#. Tôi đang tạo một ứng dụng tạo báo cáo. Thông tin sẽ được hiển thị trong báo cáo là từ Máy chủ MySQL. Tôi đã cài đặt Crystal Reports. Tuy nhiên, tôi có một số vấn đề với việc nhận dữ liệu từ MySQL vì tôi không thể tìm thấy dữ liệu từ MySQL. Dữ liệu được hiển thị trong Trình hướng dẫn tạo báo cáo không phải là các tệp cơ sở dữ liệu trong MySQL mà là các biểu mẫu tôi đã tạo trong C#. Hãy giúp tôi.Cách Tạo Báo cáo Sử dụng Báo cáo Tinh thể trong Visual Studio 2010

Ảnh chụp màn hình:

enter image description here

enter image description here

+0

Thẻ 'báo cáo-dịch vụ' không hợp lệ cho câu hỏi của bạn – niktrs

+0

Bạn nên tạo một kết nối mới để xem db mysql của bạn. – maniacneron

Trả lời

0
DataAccess.Connection.Close(); 
DataAccess.Connection.Open(); 
DataAccess.dataAdapter = new SqlDataAdapter(" SELECT sales.qty, sales.ord_date, sales.payterms, stores.stor_name, stores.stor_id, titles.title_id, titles.title, titles.price, (sales.qty * titles.price) AS Total FROM sales INNER JOIN stores ON sales.stor_id = stores.stor_id INNER JOIN titles ON sales.title_id = titles.title_id", DataAccess.Connection); 

DataAccess.dataTable = new DataTable(); 
DataAccess.dataAdapter.Fill(DataAccess.dataTable); 
Bind.DataSource = DataAccess.dataTable; 
string temp = DataAccess.dataTable.Rows[0][3].ToString(); 

Excel.Application xlApp2 = new Excel.Application(); 
xlApp2.Visible = true; 
Excel.Workbook Workbook2 = xlApp2.Workbooks.Add(1); 
Excel.Worksheet Worksheet2 = (Excel.Worksheet)Workbook2.Sheets[1]; 

Worksheet2.Cells[1, 1] = "Sales Report"; 
Worksheet2.Cells[3, 1] = temp.ToUpper(); 
Worksheet2.Cells[4, 2] = "Order Date"; 
Worksheet2.Cells[4, 3] = "Payment Terms"; 
Worksheet2.Cells[4, 4] = "Store Name"; 
Worksheet2.Cells[4, 5] = "Store ID"; 
Worksheet2.Cells[4, 6] = "Title ID"; 
Worksheet2.Cells[4, 7] = "Book Title"; 
Worksheet2.Cells[4, 8] = "Unit Price"; 
Worksheet2.Cells[4, 9] = "Total Price"; 

int intCount2 = 5; 
int TotalRec = 0; 
int finecort = 0; 
decimal cost = 0; 
decimal cost1 = 0; 

for (int n = 0; n < DataAccess.dataTable.Rows.Count; n++) 
{ 
    if (DataAccess.dataTable.Rows[n][3].ToString().Equals(temp)) 
    { 
     Worksheet2.Cells[intCount2, "C"] = DataAccess.dataTable.Rows[n][0]; 
     Worksheet2.Cells[intCount2, "B"] = DataAccess.dataTable.Rows[n][1]; 
     Worksheet2.Cells[intCount2, "D"] = DataAccess.dataTable.Rows[n][3]; 
     Worksheet2.Cells[intCount2, "E"] = DataAccess.dataTable.Rows[n][4]; 
     Worksheet2.Cells[intCount2, "F"] = DataAccess.dataTable.Rows[n][5]; 
     Worksheet2.Cells[intCount2, "G"] = DataAccess.dataTable.Rows[n][6]; 
     Worksheet2.Cells[intCount2, "H"] = DataAccess.dataTable.Rows[n][7]; 
     Worksheet2.Cells[intCount2, "I"] = DataAccess.dataTable.Rows[n][8]; 

     intCount2++; 
     TotalRec++; 
     finecort++; 
     cost += Convert.ToDecimal(DataAccess.dataTable.Rows[n][8]); 
     cost1 += Convert.ToDecimal(DataAccess.dataTable.Rows[n][8]); 
    } 
    else 
    { 
     Worksheet2.Cells[intCount2, "B"] = ("Number of records in " + temp + " group are" + TotalRec + " and the cost is R" + cost1); 
     TotalRec = 0; 
     cost1 = 0; 
     temp = DataAccess.dataTable.Rows[n][3].ToString(); 
     Worksheet2.Cells[intCount2 + 2, "A"] = temp.ToUpper(); 

     Worksheet2.Cells[intCount2 + 3, "B"] = "Order Date"; 
     Worksheet2.Cells[intCount2 + 3, "C"] = "Quantity"; 
     Worksheet2.Cells[intCount2 + 3, "D"] = "Store Name"; 
     Worksheet2.Cells[intCount2 + 3, "E"] = "Store ID"; 
     Worksheet2.Cells[intCount2 + 3, "F"] = "Title ID"; 
     Worksheet2.Cells[intCount2 + 3, "G"] = "Book Title"; 
     Worksheet2.Cells[intCount2 + 3, "H"] = "Unit Price"; 
     Worksheet2.Cells[intCount2 + 3, "I"] = "Total Price"; 

     intCount2 += 4; 
    } 
    Worksheet2.Cells.Columns.AutoFit(); 

} 

Worksheet2.Cells[intCount2, "B"] = ("Number of records in " + temp + " group=" + TotalRec); 
Worksheet2.Cells[intCount2 + 2 ,"A"] = "2013 Sales Report records added upto "; 
Worksheet2.Cells[intCount2 + 2, "B"] = finecort; 
Worksheet2.Cells[intCount2 + 3, "A"] = "Grrand Total of all records "; 
Worksheet2.Cells[intCount2 + 3, "B"] = "R"+cost; 
Worksheet2.Range[Worksheet2.Cells[1, "A"], Worksheet2.Cells[1, "I"]].Merge(); 
Worksheet2.Cells.Columns.AutoFit(); 
DataAccess.Connection.Close(); 
+0

câu trả lời này có ý nghĩa gì khi tạo báo cáo Crystal Reports trên MySQL? –

0

Here Tôi tìm thấy giải pháp phù hợp cho bạn câu hỏi.

Báo cáo tinh thể có thể sử dụng ODBC DSN để kết nối với cơ sở dữ liệu mà từ đó bạn trích xuất dữ liệu và thông tin cho mục đích báo cáo.

Lưu ý Có một vấn đề được biết đến với một số phiên bản của Crystal Reports nơi ứng dụng không thể mở và duyệt bảng và các lĩnh vực thông qua một kết nối ODBC. Trước khi sử dụng Crystal Reports với MySQL, hãy đảm bảo rằng bạn đã cập nhật lên phiên bản mới nhất, bao gồm mọi gói dịch vụ và hotfix nổi bật. Để biết thêm thông tin về số vấn đề này, hãy xem Kiến thức về Đối tượng) để biết thêm thông tin .

Thực hiện theo các bước sau:

  1. Tạo một DSN sử dụng nguồn dữ liệu (ODBC) công cụ. Bạn có thể chỉ định một cơ sở dữ liệu hoàn chỉnh, bao gồm tên người dùng và mật khẩu, hoặc bạn có thể xây dựng một DSN cơ bản và sử dụng Crystal Reports để thiết lập tên người dùng và mật khẩu.
  2. Bắt đầu Trình hướng dẫn báo cáo thẻ chéo bằng cách nhấp vào tùy chọn trên Trang bắt đầu. Mở rộng Tạo thư mục Kết nối Mới, sau đó mở rộng thư mục ODBC (RDO) để lấy danh sách các nguồn dữ liệu ODBC.
0
DataTable dataTable = new DataTable(); 

    int count1,count2; 
     clsInfor.northCON.Open(); 
     clsInfor.dataAdapter = new SqlDataAdapter("SELECT Discontinued, QuantityPerUnit FROM Products", clsInfor.northCON); 
     dataTable = new DataTable(); 
     clsInfor.dataAdapter.Fill(dataTable); 
     Excel.Application app = new Excel.Application(); //creating a new application 
     app.Visible = true; 

     Excel.Workbook book = app.Workbooks.Add(1); // creating an instance of the workbook 
     Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets[1]; // creating an instance of the worksheet 

     ((Excel.Range)sheet.Cells[1, "A"]).Value2 = "Report"; // creating the header of the report 
     ((Excel.Range)sheet.Cells[2, "B"]).Value2 = "Number of products per Cat";//creating the names of the colomns in the excell spreedsheet 
     ((Excel.Range)sheet.Cells[2, "C"]).Value2 = "Number of products that have been discontinued"; 

     ((Excel.Range)sheet.Cells[4, "D"]).Value2 = "Tot number of Prod"; 

     for (count1 = 0; count1 < dataTable.Rows.Count; count1++) 
     { 
      for (count2 = 0; count2 < dataTable.Columns.Count; count2++) 
      { 
       sheet.Cells[count1 + 3, count2 + 2] = dataTable.Rows[count1][count2]; 
      } 
      sheet.Cells.Columns.AutoFit(); 
     } 
0
 XmlDocument xmlDocument = new XmlDocument(); 
     string xmlFileName = (@"C:"); 
     xmlDocument.Load(xmlFileName); 

     XmlElement xItem = xmlDocument.CreateElement("item"); 


     XmlElement xmlSubElement1 = xmlDocument.CreateElement("todoID"); 
     xmlSubElement1.InnerText = todoID; 
     xItem.AppendChild(xmlSubElement1); 

     XmlElement xmlSubElement2 = xmlDocument.CreateElement("todoDate"); 
     xmlSubElement2.InnerText = todoDate; 
     xItem.AppendChild(xmlSubElement2); 

     XmlElement xmlSubElement3 = xmlDocument.CreateElement("todoTime"); 
     xmlSubElement3.InnerText = todoTime; 
     xItem.AppendChild(xmlSubElement3); 

     XmlElement xmlSubElement4 = xmlDocument.CreateElement("todoItem"); 
     xmlSubElement4.InnerText = todoItem; 
     xItem.AppendChild(xmlSubElement4); 

     XmlElement xmlSubElement5 = xmlDocument.CreateElement("todoStatus"); 
     xmlSubElement5.InnerText = todoStatus; 
     xItem.AppendChild(xmlSubElement5); 

     XmlElement xmlSubElement6 = xmlDocument.CreateElement("UserID"); 
     xmlSubElement6.InnerText = UserID; 
     xItem.AppendChild(xmlSubElement6); 


     //xmlDocument.AppendChild(xItem); 
     xmlDocument.DocumentElement.LastChild.AppendChild(xItem); 
     // then finally save 
     xmlDocument.Save(@"C:"); 
     xmlmsg ="A new item has been added to the to do list"; 
0
private void btndlt_Click(object sender, EventArgs e) 
    { 

     DataGridViewRow row = dataGridView1.Rows[0]; 
     string id = row.Cells[0].Value.ToString(); 
     string path = @""; 
     XmlDocument doc = new XmlDocument(); 
     doc.Load(path); 
     XmlNode node = doc.SelectSingleNode("/TheToDoList/item[todoID='" + id + "']"); 
     node.ParentNode.RemoveChild(node); 
     doc.Save(path); 
     MessageBox.Show("Selected Record Deleted Successfully"); 
    } 

    private void btnUpdate_Click(object sender, EventArgs e) 
    { 
     DataGridViewRow row = dataGridView1.Rows[0]; 
     int id1 = Convert.ToInt32(row.Cells[0].Value); 
     string path = @""; 
     XmlDocument doc = new XmlDocument(); 
     doc.Load(path); 
     XmlNode node = doc.SelectSingleNode("/TheToDoList/item[todoID='" + id1 + "']"); 
     node.ParentNode.RemoveChild(node); 
     doc.Save(path); 

       // //Load the XML File 
        doc.Load(path); 


        XmlElement root = doc.CreateElement("TheToDoList"); 
        XmlElement Subroot = doc.CreateElement("item"); 
        XmlElement todoID = doc.CreateElement("todoID"); 
        XmlElement todoDate = doc.CreateElement("todoDate"); 
        XmlElement todoTime = doc.CreateElement("todoTime"); 
        XmlElement todoItem = doc.CreateElement("todoItem"); 
        XmlElement todoStatus = doc.CreateElement("todoStatus"); 
        XmlElement UserID = doc.CreateElement("UserID"); 
        //Add the values for each nodes 
        todoID.InnerText = row.Cells[0].ToString(); 
        todoDate.InnerText = row.Cells[1].ToString(); 
        todoTime.InnerText = row.Cells[2].ToString(); 
        todoItem.InnerText = row.Cells[3].ToString(); 
        todoStatus.InnerText = row.Cells[4].ToString(); 
        UserID.InnerText = row.Cells[5].ToString(); 
        //Construct the document 
        doc.AppendChild(root); 
        root.AppendChild(Subroot); 
        Subroot.AppendChild(todoID); 
        Subroot.AppendChild(todoDate); 
        Subroot.AppendChild(todoTime); 
        Subroot.AppendChild(todoItem); 
        Subroot.AppendChild(todoStatus); 
        Subroot.AppendChild(UserID); 
        doc.Save(path); 
        MessageBox.Show("Selected Record Edited Successfully"); 
Các vấn đề liên quan