title: I am getting this error cannot implicitly convert string to system.data.datatable
body: <p>From combo selected value passing this to the stored procedure and using serialization for generating Bar Chart dashboard. But it's showing me an error </p>
  
  <blockquote>
    <p>cannot implicitly convert a string to system.data.datatable</p>
  </blockquote>
  
  <p>Using DataTable and serialization </p>
  
  <p>Error at this line</p>
  
  <pre><code>return serializer.Serialize(rows);
  </code></pre>
  
  <p>.cs code</p>
  
  <pre><code>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.Configuration;
  using System.Data.SqlClient;
  
  
  
  namespace VOT.DashboardPages
  {
      public partial class Velocity : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
              if (!this.IsPostBack)
              {
                  string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                  using (SqlConnection con = new SqlConnection(constr))
                  {
                      using (SqlCommand cmd = new SqlCommand("SELECT ProjectNo FROM [dbo].[ProjectPlan] ORDER BY ProjectNo asc"))
                      {
                          cmd.CommandType = CommandType.Text;
                          cmd.Connection = con;
                          con.Open();
                          ddlProjectNo.DataSource = cmd.ExecuteReader();
                          ddlProjectNo.DataTextField = "ProjectNo";
                          ddlProjectNo.DataValueField = "ProjectNo";
                          ddlProjectNo.DataBind();
                          con.Close();
                      }
                  }
                  ddlProjectNo.Items.Insert(0, new ListItem("--Select ProjectNo--", "0"));
              }
          }
  
              public DataTable BindData(String prjNo)
              {
                  DataTable dt = new DataTable();
                  SqlConnection connection = new SqlConnection("constr");
                  try
                  {
                      connection.Open();
                      SqlCommand sqlcmd = new SqlCommand("VelocityByOperationType", connection);
                      sqlcmd.CommandType = CommandType.StoredProcedure;
                      SqlDataAdapter sqlDa = new SqlDataAdapter(sqlcmd);
                      sqlcmd.Parameters.AddWithValue("@prjNo", prjNo);
                      sqlDa.Fill(dt);
                      System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
  
                      List&lt;Dictionary&lt;string, object&gt;&gt; rows = new List&lt;Dictionary&lt;string, object&gt;&gt;();
  
                      Dictionary&lt;string, object&gt; row;
                      foreach (DataRow dr in dt.Rows)
                      {
                          row = new Dictionary&lt;string, object&gt;();
                          foreach (DataColumn col in dt.Columns)
                          {
                              row.Add(col.ColumnName, dr[col]);
                          }
                            rows.Add(row);
                      }
  
                      return serializer.Serialize(rows);
  
                 }
                  finally
                  {
                      connection.Close();
                  }
              }
  
  
      protected void ddlProjectNo_SelectedIndexChanged(object Sender,EventArgs e)
      {
          TextBox1.Text = ddlProjectNo.SelectedItem.Value;
          DataTable dt = BindData(ddlProjectNo.SelectedItem.Value);
          //if(dt.Rows.Count&gt;0)
          //{
  
          //}
      }
  }
  </code></pre>
  
  <p>}
  <a href="https://i.stack.imgur.com/il1Bn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/il1Bn.png" alt="enter image description here"></a></p>