Archive

Posts Tagged ‘Microsoft Visual Studio’

Comma separated values in mysql


MY SQL:

GROUP_CONCAT function concatenates values within each group defined by GROUP BY clause.

Syntax GROUP_CONCAT([DISTINCT] exp [ORDER BY sorting] [SEPARATOR ‘sep’])
Quick Example SELECT GROUP_CONCAT(city) FROM cities GROUP BY state;
Separator Comma (,) by default, ” eliminates separator
NULL Values Skipped
Max Length 1024 by default, specified by group_concat_max_len system variable

Sample:

CREATE TABLE cities
   (
     city VARCHAR(70),
     state CHAR(2)
   );
 
   INSERT INTO cities VALUES ('San Francisco', 'CA');
   INSERT INTO cities VALUES ('San Diego', 'CA');
   INSERT INTO cities VALUES ('Los Angeles', 'CA');
 
   INSERT INTO cities VALUES ('Austin', 'TX');
   INSERT INTO cities VALUES ('Houston', 'TX');

   SELECT state, GROUP_CONCAT(city)
   FROM cities
   GROUP BY state;
The result:
CA San Francisco,San Diego,Los Angeles
TX Austin,Houston
SQL Server:
SELECT state,
STUFF((SELECT ',' + city FROM cities WHERE state = c.state FOR XML PATH('')),1 ,1 ,'')
FROM cities c
GROUP BY state

Hope this help !
Rahul Bhatia

How to create a Pie chart using ASP.Net and C#

December 23, 2013 Leave a comment

43

 

There are 4 things you need to do in order to get this configured and working on your machine, remember, however that you will need Visual Studio 2010 and .Net 4.
  • Create a Website project
  • Modify the Web.Config file
  • Modify the Default.aspx file
  • Modify the Default.aspx.cs file
I’ll assume you know how to create a Website project…File, New, Website, ASP.Net project…
The Web.Config file needs to be modified to contain the httpHandler and controls. These configurations enable the asp:Chart tag which is used in the Default.aspx file.

<httpHandlers>

  <add path="ChartImg.axd"
      verb="GET,HEAD,POST"
      type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,System.Web.DataVisualization,
      Version=4.0.0.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35"
      validate="false"/>
</httpHandlers>
<controls>
  <add tagPrefix="asp"
      namespace="System.Web.UI.DataVisualization.Charting"
      assembly="System.Web.DataVisualization,
      Version=4.0.0.0,
      Culture=neutral,
      PublicKeyToken=31bf3856ad364e35"/>
</controls>
In the Default.aspx file we will add the chart, titles, legend, series and chartareas.

<asp:chart id="Chart1" runat="server" Height="300px" Width="400px">

  <titles>
    <asp:Title ShadowOffset="3" Name="Title1" />
  </titles>
  <legends>
    <asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False"
    Name="Default" LegendStyle="Row" />
  </legends>
  
  <series>
    <asp:Series Name="Default" />
  </series>
  <chartareas>
    <asp:ChartArea Name="ChartArea1" BorderWidth="0" />
  </chartareas>
</asp:chart> 
And lastly, we will add the code to the code-behind file to populate and configure the chart. First thing I do is to load the data values for the chart. If this was implemented in a program being used to represent real data, then the values would not be hardcoded. You would connect to a database, run a query and then have your business logic create the contents of the values. For simplicity, I hard coded the values. Then I simply went through and set the properties that created the above Pie Chart.

protected void Page_Load(object sender, EventArgs e)

{
  double[] yValues = { 71.15, 23.19, 5.66 };
  string[] xValues = { "AAA", "BBB", "CCC" };
  Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);
  Chart1.Series["Default"].Points[0].Color = Color.MediumSeaGreen;
  Chart1.Series["Default"].Points[1].Color = Color.PaleGreen;
  Chart1.Series["Default"].Points[2].Color = Color.LawnGreen;
  Chart1.Series["Default"].ChartType = SeriesChartType.Pie;
  Chart1.Series["Default"]["PieLabelStyle"] = "Disabled";
  Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
  Chart1.Legends[0].Enabled = true;
}
Hope this help !

Visual Studio warning: “Some of the properties associated with the solution could not be read”

December 4, 2013 Leave a comment

I just fixed a similar issue with a VS2010 solution with 42 projects… The cause was a duplicated

GlobalSection(TeamFoundationVersionControl)

section in the solution file. I closed the solution, removed the duplicate GlobalSection(TeamFoundationVersionControl) config and reloaded the solution and the warning message was gone.

Hope this help!

Unable to write to output file [FileName] .pdb: Unspecified error Visual Studio

July 12, 2013 1 comment

“Unable to write to output file [FileName] .pdb: Unspecified error” for one of the projects.

I have cleaned the project solution , deleting references but that didn’t help

Figured out that there was a missing file in one of the projects. To know which file it is please follow the steps

[1] Close visual studio

[2] Reopen the solution (DON’T build)

[3] Check the Errors List

You should see

Error    1    Unable to open module file [FileName].vb : The system cannot find the file specified.    [FileName] [Project]

Hope its helps!

 

Visual Studio – Database Project Not Loading


Have you ever created a Database project and after some time you are not able to load it in the Visual Studio? Probably you might be getting following error:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)

The database project requires an active database connection to load at design time. Probably it uses that to compile/verify scripts. The problem here is Visual Studio is not able to connect to any such instance. Following are few solutions (these worked for me)

  1. Make sure the instance to which you want to connect is running and allows remote connections.
  2. After performing step 1, if it is still not loading then you may need to start the SQL Browser Service. Make sure it’s running.
  3. If the problem is still there, it has to be fixed from Visual Studio itself. Actually database project do not store to which instance it can connect. It’s a Visual Studio setting.In VS2008 go to Tool > Options > Database Tools > Design-time Validation Database > Connection Options. Specify your instance name here like “\SQLEXPRESS”

Also If you upgraded your database project from 2005 to 2008 and if  you try to open the 2008 database project solution file then you may get the following error:

Coluld not load file or assembly ‘System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken = 89845dcd8080cc91’ or one of its dependencies. The system cannot find the file specified.

To resolve this you need to install SQL Server CE 3.5 SP1 from here: http://www.microsoft.com/downloads/details.aspx?FamilyID=dc614aee-7e1c-4881-9c32-3a6ce53384d9&displaylang=en

Hope it helps !