I am novice developer who is trying to implement google charts to read of the sql database. I can not get the charts to render on the page, at the moment.
aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Charts_07.aspx.cs" Inherits="Charts_07" %>
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
cs. class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Configuration;
public partial class Charts_07 : System.Web.UI.Page
{
StringBuilder str = new StringBuilder();
//Get connection string from web.config
SqlConnection conn = new SqlConnection("Data Source=MISBAH\\SQLEXPRESS;Initial Catalog=Test;Persist Security Info=True;User ID=ma;Password=misbah");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
chart_bind();
}
}
private DataTable GetData()
{
DataTable dt = new DataTable();
conn.Open();
string cmd = "select * from data";
SqlDataAdapter adp = new SqlDataAdapter(cmd, conn);
adp.Fill(dt);
conn.Close();
return dt;
}
private void chart_bind()
{
DataTable dt = new DataTable();
try
{
dt = GetData();
str.Append(@"");
lt.Text = str.ToString().TrimEnd(',').Replace('*', '"');
}
catch
{ }
}
}
database schema:
INSERT INTO [dbo].[data]
([Id]
,[name]
,[data]
,[cover]
,[talk]
,[date])
VALUES
(
,
,
,
,
,)
GO
Any assistance or help would be very much appreciated.
Satyapriya NayakPosted Nov 23, 2013, 11:21 AM