Feeds:
Posts
Comments

Recently came across a nice and easy way to retrieve List of Table and Views from SQL Server database.

The idea is to use SQL statement to query some system tables holding the schemas

using

SELECT RTRIM(tbl.table_name) AS TableName
FROM INFORMATION_SCHEMA.TABLES tbl
WHERE tbl.TABLE_TYPE = ‘BASE TABLE’

Will get all Tables in a database.

Using “VIEW” instead of “BASE TABLE” will retrieve the List of Views.

 

And to go one step further, we can get details of columns in each table using

 

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS col
WHERE col.TABLE_NAME = ‘TableName’

The will show details of each column ( type, nullable or not, max capacity, ID or not, default value, etc.)

A revolutionary new way to do command line anc batch files for the windows OS. PowerShell is able to deal with “Objects” rather than mere strings and builds on the .NET Framework 2.0 Objects.

A nice series of webcasts can be found here (http://www.microsoft.com/technet/scriptcenter/webcasts/ps.mspx)

SQL Server 2005 SP2

 

Service Pack 2 is released for SQL server 2005.

It is available Here

Google Code Search

Google launched a new service to search for source Code. It is part of google labs.

http://www.google.com/codesearch

 

There is a subtle note about using the “foreach” enumeration. The “foreach” uses an enumerator that assumes that the number of elements in the collection will remain intact during the enumeration.

If this changes, an exception “Collection was modified, Enumeration Operation may not execute”.

 

what that means is:

you can NOT do something like

foreach(datarow row in table.rows)

{

if (some condition)

{

     table.rows.remove(row);

}

 

trying to remove a row form within the enumeration will throw an exception.

 

 

A better way to do it is :

 

for(int x =  table.rows.count-1; x>=0; x– )

{

if (some condition)

{

     table.rows.remove(row);

}

Note that the for loop is a decrementing loop (x–) to avoid having problems with the rows position when one or more rows are removed from the collection

I hve came across an issue today:
I wanted to copy some datarows from one table to another.

I tried first to do this:

foreach(DataSetSource.Row row in tableSource)
{
tableDestination.Add Row(row);
}
It compiled with no errors but at run time threw exception saying “row already belongs to another table”

So I found some other way to do it :

foreach(DataSetSource.Row row in tableSource)
{
tableDestination.Rows.Add(row.ItemArray);
}

and this way it worked just fine.

CodeFetch

 

CodeFetch.com  is a new web site that has a search engine where you can look up code used in programming books.

I found it first at  Chris Sell’s Blog

http://www.sellsbrothers.com/news/showTopic.aspx?ixTopic=2070

 

Interesting:)

Since ASP.NET 2.0 compilation is different than the previous ASP.NET 1.x model, it is not obvious for web developers where are the DLLs to which the FxCop should be pointing to for analysis.

I have recently found this simple and effective solution posted  http://www.madskristensen.dk/blog/Use+FxCop+With+ASPNET+20.aspx.

In the post you will see steps of how to do it.

What he suggests in simple words is to publish the web site to a folder which will make the visual studio copy the DLL files there and then point the FxCop to the DLLs there.

Note: if using the Visual studio team suite, no need to worry about this as the built in code analysis tool handles this issue transparently.

FxCop home page and downloads can be found at http://www.gotdotnet.com/Team/FxCop/

It is not allowed to have overloaded web methods. Trying to do so will not result in compile error but will generate a runtime error saying something like “Error: two methods having name”.

 

A possible workaround for this situation is to use the MessageName Property for the webmethod Attribute.

Example:

The following Code will cause errors

*********************************************

[WebMethod]

public string GetStatus(string username)

{

return “status1”;

}

[WebMethod]

public string GetStatus(int userId)

{

return “status1”;

}

***************************************************

 

A possible solution could be :

 

*********************************************

[WebMethod(MessageName=”GetStatusByName”)]

public string GetStatus(string username)

{

return “status1”;

}

[WebMethod(MessageName=”GetStatusById”)]

public string GetStatus(int userId)

{

return “status1”;

}

***************************************************

In order to automatically scroll to the end of a text box in a windows forms, simply add the following code.

this.txtResults.Text += “\r\n” + newLineData; // newLineData is string added as new line
this.txtResults.Select(this.txtResults.Text.Length, 0);
this.txtResults.ScrollToCaret();

where txtResults is the textbox in question.

Also you need to make sure that the textbox is a multiline AND it has a vertical scroll bar.

That simple code will make the text automatically scroll to the end of the text box.