SELECT *
FROM Person.Address A
INNER JOIN (SELECT AddressLine1, City
FROM Person.[Address]
GROUP BY AddressLine1, City
HAVING COUNT(*) > 1) AS A1
ON A.AddressLine1 = A1.AddressLine1
AND A.City = A1.City
ORDER BY A.AddressLine1, A.City, A.AddressID
Wednesday, March 17, 2010
Monday, March 1, 2010
how to get a list of tables in a database using C#
Unsurprisingly, if a table doesn't exist in a database, you can't use a select query to determine whether it exists. But using GetSchema() with no parameters, you can obtain a schema table, which is essentially a list of tables you can specify to get more specific schema information. In this case, I wanted to get a list of tables in the database. After transforming the results into a list of strings, I could then safely search the list to determine whether it exists.
Schema and metadata retrieval using ADO.NET
this also works, depending on whether you need these extra parameters, but its a big uglier:
Get all table names
SqlConnection con =
new SqlConnection("connection_string");
con.Open();
DataTable tbl =
con.GetSchema("Tables");
Schema and metadata retrieval using ADO.NET
this also works, depending on whether you need these extra parameters, but its a big uglier:
DataTable tables =
con.GetOleDbSchemaTable
(OleDbSchemaGuid.Tables,
new object[]{null,null,null,"TABLE"});
Get all table names
Wednesday, February 24, 2010
fixed my "Restore failed...The file cannot be overwritten. It is being used by database..." error
The "Database -> Restore Database... -> Options pane -> Restore the database files as" file names in the "Restore As" fields were not "Test1Copy1" as entered into the "General pane -> Destination for restore -> To database" field as the database restore destination. The file names were in fact "Test1," the same name of the "General pane -> Destination for restore -> From database" field. Basically, the file names should be Test1Copy1, but for some reason default to Test1.
The... error is resolved by clicking into the "Options pane -> Restore the database files as" file names in the Restore As fields and manually changing the file names...
FROM: Test1.mdf
TO: Test1Copy1.mdf
and
FROM: Test1_log.ldf
TO: Test1Copy1_log.ldf
This could be a SQL Server Management Studio bug, but it is just as likely a misunderstanding by a user who is just realizing he not only doesn't know his @ss from a hole in the ground; he didn't even know there was a hole in the ground ;-)
<%= Clinton Gallagher
Slightly scathing at the very end, Clinton Gallagher, very sneaky, but I do appreciate the apparent concern for my virgin eyes and for the bug fix :-P
http://www.sqlnewsgroups.net/group/microsoft.public.sqlserver.server/topic12008.aspx
The... error is resolved by clicking into the "Options pane -> Restore the database files as" file names in the Restore As fields and manually changing the file names...
FROM: Test1.mdf
TO: Test1Copy1.mdf
and
FROM: Test1_log.ldf
TO: Test1Copy1_log.ldf
This could be a SQL Server Management Studio bug, but it is just as likely a misunderstanding by a user who is just realizing he not only doesn't know his @ss from a hole in the ground; he didn't even know there was a hole in the ground ;-)
<%= Clinton Gallagher
Slightly scathing at the very end, Clinton Gallagher, very sneaky, but I do appreciate the apparent concern for my virgin eyes and for the bug fix :-P
http://www.sqlnewsgroups.net/group/microsoft.public.sqlserver.server/topic12008.aspx
Thursday, February 18, 2010
fixed my " TypeLoadException: Could not load type from string value" error
3.2.4.1. Object creation of generic types via constructor invocation
The following examples shows the definition of simple generic types and how they can be created in Spring's XML based configuration file.
The XML configuration to create and configure this object is shown below
Chapter 3. Objects, Object Factories, and Application Contexts
The following examples shows the definition of simple generic types and how they can be created in Spring's XML based configuration file.
namespace GenericsPlay
{
public class FilterableList<T>
{
private List<T> list;
private String name;
public List<T> Contents
{
get { return list; }
set { list = value; }
}
public String Name
{
get { return name; }
set { name = value; }
}
public List<T> ApplyFilter(string filterExpression)
{
/// should really apply filter to list ;)
return new List<T>();
}
}
}
The XML configuration to create and configure this object is shown below
<object id="myFilteredIntList" type="GenericsPlay.FilterableList<int>, GenericsPlay">
<property name="Name" value="My Integer List"/>
</object>
Chapter 3. Objects, Object Factories, and Application Contexts
Monday, February 8, 2010
Friday, January 8, 2010
how to add a Global.asax code behind file
One of the subtle differences I've found while working with web projects in Visual Studio 2005 is the Global.asax code is placed in script tags within the actual .asax page, not a codebehind file, as it was with .NET 1.1. This article describes how to set up the Global.asax file to utilize the Global.asax.cs codebehind file.
First off, go to files->add new and select the "Global Application Class" file. You'll notice right off the bat that the option to put the code in a separate file is grayed out. Ignore this and click "Add".
Next, go back to files->add new and select a "Class" file. Type in the name "Global.asax.cs" and click "Add". Visual Studio will prompt you to add this file to the App_Code directory, select "Yes" and continue.
Now that the files are in place, we need to do some slight manipulation of the existing code to get this solution to compile.
To start, the Global class in the Global.asax.cs file needs to implement HttpApplication.
public class Global : System.Web.HttpApplication
Next, move the code within the script tags from the Global.asax file to the Global.asax.cs file -within the Global class.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
...snip...
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
}
Once the code has been moved, remove the script tags from Global.asax:
Add the following to the Application directive at the top of the same page:
CodeBehind="Global.asax.cs" Inherits="Global"
The entire contents of the Global.asax file should look like:
<%@ Application Language="C#" CodeBehind="Global.asax.cs" Inherits="Global" %>
The solution should compile and the Global events should fire correctly as well.
http://www.xerratus.com/2006/10/20/NET20GlobalasaxCodeInSeparateFile.aspx
First off, go to files->add new and select the "Global Application Class" file. You'll notice right off the bat that the option to put the code in a separate file is grayed out. Ignore this and click "Add".
Next, go back to files->add new and select a "Class" file. Type in the name "Global.asax.cs" and click "Add". Visual Studio will prompt you to add this file to the App_Code directory, select "Yes" and continue.
Now that the files are in place, we need to do some slight manipulation of the existing code to get this solution to compile.
To start, the Global class in the Global.asax.cs file needs to implement HttpApplication.
public class Global : System.Web.HttpApplication
Next, move the code within the script tags from the Global.asax file to the Global.asax.cs file -within the Global class.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
...snip...
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
}
Once the code has been moved, remove the script tags from Global.asax:
Add the following to the Application directive at the top of the same page:
CodeBehind="Global.asax.cs" Inherits="Global"
The entire contents of the Global.asax file should look like:
<%@ Application Language="C#" CodeBehind="Global.asax.cs" Inherits="Global" %>
The solution should compile and the Global events should fire correctly as well.
http://www.xerratus.com/2006/10/20/NET20GlobalasaxCodeInSeparateFile.aspx
Wednesday, December 30, 2009
Programming and Software Development Quotes
Some of my favorites from some of his favorites:
“Good design adds value faster than it adds cost.”
- Thomas C. Gale
“Better train people and risk they leave – than do nothing and risk they stay.”
- Unknown
“Think twice before you start programming or you will program twice before you start thinking.”
- Unknown
“Debugging is like farting – it’s not so bad when it’s your own code.”
- Unknown
“Confidence, n.: The feeling you have before you understand the situation”
- Unknown
“Good judgement is the result of experience … Experience is the result of bad judgement.”
- Fred Brooks
“Your code is both good and original. Unfortunately the parts that are good are not original, and the parts that are original are not good.”
- Unknown
“Now I’m a pretty lazy person and am prepared to work quite hard in order to avoid work.”
- Martin Fowler
And the last one is actually someone I work with!!! Well, its a guy with the same name as the guy I work with and who is often mistaken for the great Martin Fowler!
http://daipratt.co.uk/programming-and-it-quotes/
“Good design adds value faster than it adds cost.”
- Thomas C. Gale
“Better train people and risk they leave – than do nothing and risk they stay.”
- Unknown
“Think twice before you start programming or you will program twice before you start thinking.”
- Unknown
“Debugging is like farting – it’s not so bad when it’s your own code.”
- Unknown
“Confidence, n.: The feeling you have before you understand the situation”
- Unknown
“Good judgement is the result of experience … Experience is the result of bad judgement.”
- Fred Brooks
“Your code is both good and original. Unfortunately the parts that are good are not original, and the parts that are original are not good.”
- Unknown
“Now I’m a pretty lazy person and am prepared to work quite hard in order to avoid work.”
- Martin Fowler
And the last one is actually someone I work with!!! Well, its a guy with the same name as the guy I work with and who is often mistaken for the great Martin Fowler!
http://daipratt.co.uk/programming-and-it-quotes/
Subscribe to:
Posts (Atom)