tag:blogger.com,1999:blog-38578135724979800312024-03-13T00:51:45.322+00:00Code LawsSimple blog detailing code examples for both vb.net, c# and PHP and hints and tips for Crystal Reports.Unknownnoreply@blogger.comBlogger28125tag:blogger.com,1999:blog-3857813572497980031.post-35304037517199635412019-07-18T15:57:00.002+01:002019-07-18T15:57:13.917+01:00C# - using a dll with code behind 1This is an example of using a dll file to call data from to populate a c# code behind file.<br />
<br /><br />
1. An example of a dll file to call data from a sql database<br />
<br /><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Collections.Generic;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Collections;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.ComponentModel;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Configuration;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Data.Common;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Data.Odbc;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Data.OleDb;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Data.Sql;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Data.SqlClient;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Data.SqlTypes;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Data;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Diagnostics;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Drawing;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.IO;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Linq;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Net.Mail;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Net;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Runtime.Serialization.Formatters.Binary;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Security.Principal;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Text.RegularExpressions;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Text;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> Microsoft.VisualBasic;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Web;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> System.Xml;</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">namespace</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> TestLibrary1</span></span></span><br />
<span style="background-color: yellow;"><br /></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">{</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">public</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">class</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">DataBaseDll3</span></span></span></span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; color: #2b91af; font-family: Consolas; font-size: x-small;">
</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> {</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<br /></span><span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">public</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> DataSet GetData1(</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">string</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> cmdText)</span></span></span><br />
<span style="background-color: yellow;"><br /></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> {</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<br /></span><span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> DataSet dt = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> DataSet(</span></span><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;">"Test"</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">);</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><br />
<span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> SqlCommand cmd = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> SqlCommand();</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><br />
<span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> SqlDataAdapter da = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> SqlDataAdapter();</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><br />
<span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> (SqlConnection con = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> SqlConnection(ConfigurationManager.ConnectionStrings[</span></span><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;">"LIVE"</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">].ConnectionString))</span></span></span><br />
<span style="background-color: yellow;"><br /></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> {</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> da.SelectCommand = con.CreateCommand();</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> da.SelectCommand.CommandType = CommandType.Text;</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> da.SelectCommand.CommandText = cmdText;</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> da.SelectCommand.Connection = con;</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<br />
<span style="background-color: yellow;"><br /></span></span><span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">try</span></span></span></span><br />
<span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; color: blue; font-family: Consolas; font-size: x-small;">
</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">{</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> con.Open();</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> da.Fill(dt);</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> con.Close();</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">}</span></span><br />
<br /></span><span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">catch</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> (Exception ec)</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> { }</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; color: blue; font-family: Consolas; font-size: x-small;">finally</span></span></span></span><br />
<br /></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> {</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> con.Close();</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> }</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"><br /></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"> }</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">
</span></span><br />
<br /></span><span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">return</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> dt;</span></span></span><br />
<span style="background-color: yellow;"><br /></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;"><br /></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow;">}</span><br />
<span style="background-color: yellow;">
</span><br />
<span style="background-color: yellow;"> }</span><br />
<br /><br />
DON'T FORGET TO ADD THE CONNECTION STRING IN THE WEB.CONFIG FILE IN THE DLL<br />
<br /><br />
Then to call the result in the Code Behind..<br />
<br /><br />
ADD <br />
<br /><br />
<br />
<span style="background-color: yellow;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> <name class="" library="" of="">;</name></span></span></span><br />
<br /><br />
Add the .dll file through the Reference Folder in Visual Studio<br />
<br /><br />
Use Browse and find the file in the bin/debug folder.<br />
<br /><br />
The add the follow code to call the DataSet .dll result...<br />
<br /><br />
<br /><br />
<br />
<span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">DataBaseDll3 db2 = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> DataBaseDll3();</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><br />
<span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> Global.ds = db2.GetData1(</span></span><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;">"Select GetDate();"</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">);</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="background-color: yellow; font-family: Consolas; font-size: x-small;">
</span></span><br />
<span style="background-color: yellow;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">string</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> test2 = Global.ds.Tables[0].Rows[0][0].ToString();</span></span></span></span><br /><br />
<br /></span><br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-35312671301086497562019-06-28T15:32:00.000+01:002019-06-28T15:32:31.205+01:00XML - Read XML data type from SQL database in C#<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">The code below pulls the Column with XML Data Type from the table in the SQL DATABASE</span></span><br />
<span style="font-family: Consolas; font-size: x-small;">and keeps the data in XML format in c#.</span> <span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"></span></span></span><br />
<span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /></span></span></span><br />
<span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">string</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> connStr = ConfigurationManager.ConnectionStrings[</span></span><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;">"Test"</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">].ConnectionString;</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">string</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> query = </span></span><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;"><span style="color: #a31515; font-family: Consolas; font-size: x-small;">"<select appended="" by="" statement=""> FOR XML AUTO, ROOT"</select></span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">;</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;">// wrap your SqlConnection and SqlCommand in using blocks...</span></span></span><br />
<span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;">
</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> (SqlConnection _con = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> SqlConnection(connStr))</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">
</span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> (SqlCommand _cmd = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> SqlCommand(query, _con))</span></span><br />
<br />
<span style="font-family: Consolas; font-size: x-small;"><br />
<span style="font-family: Consolas; font-size: x-small;">
<br />
{<br />
</span><br /></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;">// setup parameter for _cmd</span></span></span><br />
<span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;">
</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;">// _cmd.Parameters.Add("@ID", SqlDbType.Int).Value = 1;</span></span></span><br />
<span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;">
</span></span></span><br />
<span style="font-family: Consolas; font-size: x-small;"><br />
<span style="font-family: Consolas; font-size: x-small;">
<br />
_con.Open();<br />
</span><br /></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">string</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> contentsOfYourXml = (</span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">string</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">)_cmd.ExecuteScalar();</span></span><br />
<br />
<span style="font-family: Consolas; font-size: x-small;"><br />
<span style="font-family: Consolas; font-size: x-small;">
<br />
_con.Close();<br />
<br />
Label1.Text = contentsOfYourXml;<br />
<br />
}</span><br /></span><br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-49163854757135526672011-08-02T08:08:00.002+01:002011-08-02T08:10:54.840+01:00SQL Command - DataTextField for Drop Down List in Gridview@theID int<br />AS SELECT<br />A.D_ID,<br />CONVERT(CHAR(5), A.D_Time, 114) as D_Time,<br />A.D_Cardiac_Rhythm,<br />b.CARD_Name,<br />A.D_Joules,<br />A.D_Drug,<br />D.L_Description,<br />A.D_Dose,<br />c.DOSE_NAME,<br />A.D_Notes<br />FROM DETAILS a<br />INNER JOIN CARDIAC_RHYTHM b <br />ON a.D_Cardiac_Rhythm = b.CARD_ID JOIN DOSE c <br />ON a.D_Dose = c.DOSE_ID JOIN LOOKUP_TEXT d <br />ON a.D_Drug = d.L_ID<br />WHERE<br />a.D_E_ID = @theIDUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-36797634176560960182011-07-21T14:25:00.005+01:002011-07-21T14:30:33.397+01:00ASP.NET Displaying XML in a XSLTQuite simple this one, don't bother about using either c# or vb.net<br /><br />Just use this line in the aspx code between the form tags....<br /><br /><span style="color:#ffff33;">asp:xml id="ID" runat="server" documentsource="tool.xml" transformsource="tool.xsl"/<br /></span><span style="color:#ffff33;"></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-63402590893504633442011-07-12T15:10:00.006+01:002011-07-12T15:18:07.994+01:00IF statement in SQL Stored ProcedureA nifty little SQL code here, that checks if a value exists in a SQL table, and if it finds the value doesn't exist will insert the value....<br /><br />First declare and set the variable<br /><span style="color:#ffff33;">DECLARE @patientID VARCHAR(30)<br />SET @patientID = 'xxxxxxx'<br /></span><br />next write the if statement to check if the value already exists in the table<br /><span style="color:#ffff33;">if exists(Select * From episodes<br />Where <a href="mailto:patient_id=@patientID">patient_id=@patientID</a>)</span><br /><span style="color:#ffff33;"><br /><br /><br /><br /><p></span></p>If it exists return and end the function<br /><span style="color:#ffff33;">begin<br />return<br />end</span><br /><br /><br /><br /><br /><p>Else insert the value into the table<br /><span style="color:#ffff33;">else<br />begin<br />INSERT INTO episodes(patient_id)<br />values(@patientID)</span><br /></p><br /><br /><p>End the statement</p><span style="color:#ffff33;">end<br />Go</span> <br /><p><span style="color:#000000;">And thats it, of course if you wish you can write this as a stored procedure. Good Luck.</span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-4054774220442281232011-07-11T12:47:00.004+01:002011-07-11T13:00:46.478+01:00Show Footer on Gridview binded from SQLDataSourceToday, is a little simple but very helpful piece of code in both c#and vb.net. This is a demonstration of how to show the footer and bind a blank row to a DataGrid that has been binded form the SQLDataSource.<br /><br />Firstly, in the page load, enter the following code at the end of all other code.<br /><br />In c#<br /><br /><span style="color:#ffff66;">int rowcount = GridView1.Rows.Count;<br />if (rowcount == 0)<br />{bindCount();<br />}<br /></span><br />and in vb.net<br /><br /><span style="color:#ffff33;">Dim rowcount As Integer = GridView1.Rows.Count<br />If rowcount = 0 Then<br />bindCount()<br />End If<br /></span><br />Then create the following void to create a false row and show the footer.<br /><br /><br /><span style="color:#ffff33;">void bindCount()<br />{<br />GridView1.DataSourceID = null;<br />GridView1.DataSource = null;<br />DataTable dt = new DataTable();<br />string FirstC = "episode_id";<br />DataColumn dCol1 = new DataColumn(FirstC, typeof(System.String));<br />string SecondC = "code";<br />DataColumn dCol2 = new DataColumn(SecondC, typeof(System.String));<br />string ThirdC = "value";<br />DataColumn dCol3 = new DataColumn(ThirdC, typeof(System.String));<br />string FourthC = "description";<br />DataColumn dCol4 = new DataColumn(FourthC, typeof(System.String));<br />string FifthC = "theTimestamp";<br />DataColumn dCol5 = new DataColumn(FifthC, typeof(System.String));<br /><br />dt.Columns.Add(dCol1);<br />dt.Columns.Add(dCol2);<br />dt.Columns.Add(dCol3);<br />dt.Columns.Add(dCol4);<br />dt.Columns.Add(dCol5);<br />for (int i = 0; i <= 0; i++) {<br />DataRow row1 = dt.NewRow();<br />row1[FirstC] = "";<br />row1[SecondC] = "";<br />row1[ThirdC] = "";<br />row1[FourthC] = "";<br />row1[FifthC] = "";<br />dt.Rows.Add(row1);<br />}<br />foreach (DataColumn col in dt.Columns) {<br />BoundField bField = new BoundField();<br />bField.DataField = col.ColumnName;<br />bField.HeaderText = col.ColumnName;<br />GridView1.Columns.Add(bField);<br />}<br />GridView1.DataSource = dt;<br />GridView1.Columns[6].Visible = false;<br />GridView1.Columns[7].Visible = false;<br />GridView1.Columns[8].Visible = false;<br />GridView1.Columns[9].Visible = false;<br />GridView1.Columns[10].Visible = false;<br />GridView1.DataBind();<br />}<br /></span><br />and in vb.net<br /><br /><span style="color:#ffff33;">Private Sub bindCount()<br />GridView1.DataSourceID = Nothing<br />GridView1.DataSource = Nothing<br />Dim dt As New DataTable()<br /><br />Dim FirstC As String = "episode_id"<br />Dim dCol1 As New DataColumn(FirstC, GetType(System.String))<br /><br />Dim SecondC As String = "code"<br />Dim dCol2 As New DataColumn(SecondC, GetType(System.String))<br /><br />Dim ThirdC As String = "value"<br />Dim dCol3 As New DataColumn(ThirdC, GetType(System.String))<br /><br />Dim FourthC As String = "description"<br />Dim dCol4 As New DataColumn(FourthC, GetType(System.String))<br /><br />Dim FifthC As String = "theTimestamp"<br />Dim dCol5 As New DataColumn(FifthC, GetType(System.String))<br /><br />dt.Columns.Add(dCol1)<br />dt.Columns.Add(dCol2)<br />dt.Columns.Add(dCol3)<br />dt.Columns.Add(dCol4)<br />dt.Columns.Add(dCol5)<br /><br />For i As Integer = 0 To 0<br />Dim row1 As DataRow = dt.NewRow()<br />row1(FirstC) = ""<br />row1(SecondC) = ""<br />row1(ThirdC) = ""<br />row1(FourthC) = ""<br />row1(FifthC) = ""<br />dt.Rows.Add(row1)<br />Next<br /><br />For Each col As DataColumn In dt.Columns<br />Dim bField As New BoundField()<br />bField.DataField = col.ColumnName<br />bField.HeaderText = col.ColumnName<br />GridView1.Columns.Add(bField)<br />Next<br /><br />GridView1.DataSource = dt<br />GridView1.Columns(6).Visible = False<br />GridView1.Columns(7).Visible = False<br />GridView1.Columns(8).Visible = False<br />GridView1.Columns(9).Visible = False<br />GridView1.Columns(10).Visible = False<br />GridView1.DataBind()<br /><br />End Sub<br /><br /></span>This example has been produced on a datagrid that has 5 columns. Depending how many columns your datagrid has, increase or decrease the number of columns accordingly. This code need to take in to consideration any invisible columns you may have.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-35319185752166257632011-07-06T09:44:00.001+01:002011-07-06T09:45:24.998+01:00Checkbox Checked in GridviewJust a little bit of code, which can be used in GridView to find out which row/id has been checked by a checkbox in a Gridview, this one might need some hashing about.<br /><br /><br />Sub chkStatus_OnCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)<br />' MsgBox("CHECKED!")<br />Dim checkbox As CheckBox = DirectCast(sender, CheckBox)<br />Dim row As GridViewRow = DirectCast(checkbox.NamingContainer, GridViewRow)<br />Dim UserId As Integer = CInt(GridView1.DataKeys(row.DataItemIndex).Value)<br />Dim UserInfo As String = ""<br />Dim Status As Boolean = checkbox.Checked<br />Dim strStatus As String = ""<br />UserInfo = " ("<br />UserInfo += GridView1.Rows(row.DataItemIndex).Cells(1).Text + " "<br />UserInfo += GridView1.Rows(row.DataItemIndex).Cells(4).Text<br />UserInfo += ")"<br />If Status Then<br />strStatus = "Approved"<br />Else<br />strStatus = "NOT Approved"<br />End If<br />' MsgBox("CheckBox1_CheckedChanged Fired for User Id = " + UserId.ToString + UserInfo + " and new status is " + strStatus + "<br /><br />")<br />heldCodes.Text = heldCodes.Text + "," & UserId.ToString<br />Dim t1 As TextBox = DirectCast(sender, TextBox)<br />Dim t2 As String = GridView1.Rows(row.DataItemIndex).Cells(2).Text<br />Dim t3 As String = GridView1.Rows(row.DataItemIndex).Cells(3).Text<br />Dim t4 As String = GridView1.Rows(row.DataItemIndex).Cells(4).Text<br />'Line below works<br />'Dim t As TextBox = DirectCast(Me.GridView1.Rows(0).Cells(1).FindControl("lbl_quantity"), TextBox)<br />Dim c As CheckBox = DirectCast(Me.GridView1.Rows(0).Cells(1).FindControl("lbl_checkbox"), CheckBox)<br />'MsgBox("This is the TextBox text in the GridView: " & t.Text)<br /><br />End SubUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-80581527536040599452011-06-09T11:31:00.004+01:002011-06-09T11:38:51.205+01:00XML - Reading from an XML Document.Finally how to read from a XML Document, with this little script for a page.<br /><br />use the following for c#<br /><br /><span style="color:#ffff33;">protected void Page_Load(object sender, EventArgs e)<br />{<br />XmlDocument xmlDoc = new XmlDocument();<br />DataSet mycountries = new DataSet();<br />mycountries.ReadXml(MapPath("text_xml.xml"));<br /><br />rb.DataSource = mycountries;<br />rb.DataValueField = "value";<br />rb.DataTextField = "design";<br />rb.DataBind();<br /><br />xmlDoc.Load(MapPath("text_xml.xml"));<br /><br />XmlNodeList xmlnodelist = xmlDoc.DocumentElement.ChildNodes;<br />XmlNode xmlnode = xmlnodelist.Item(0);<br />int xmlcount = xmlnodelist.Count;<br /><br />TextBox1.Text = xmlnode["design"].InnerText;<br />TextBox2.Text = xmlnode["value"].InnerText;<br /><br />Body.Style.Add("background-color", xmlnode["backcolor"].InnerText);<br />XmlNode xmlnode2 = xmlnodelist.Item(1);<br />TextBox2.Text = xmlnode2["value"].InnerText;<br /><br />}<br />protected void Button1_Click(object sender, EventArgs e)<br />{<br />XmlDocument xmlDoc = new XmlDocument();<br />xmlDoc.Load(MapPath("text_xml.xml"));<br />XmlNodeList xmlnodelist2 = xmlDoc.DocumentElement.ChildNodes;<br />XmlNode xmlnode2 = xmlnodelist2.Item(1);<br />TextBox1.Text = xmlnode2["design"].InnerText;<br />Body.Style.Add("background-color", xmlnode2["backcolor"].InnerText);<br />Body.Style.Add("color", "white");<br /><br />} </span><br /><br /><br />or in vb.net use:<br /><br /><span style="color:#ffff33;">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br />Dim xmlDoc As New XmlDocument<br /><br /><br />Dim mycountries = New DataSet<br />mycountries.ReadXml(MapPath("text_xml.xml"))<br /><br />rb.DataSource = mycountries<br />rb.DataValueField = "value"<br />rb.DataTextField = "design"<br />rb.DataBind()<br /><br />xmlDoc.Load(MapPath("text_xml.xml"))<br /><br />Dim xmlnodelist As XmlNodeList = xmldoc.DocumentElement.ChildNodes<br />Dim xmlnode As XmlNode = xmlnodelist.Item(0)<br />TextBox1.Text = xmlnode("design").InnerText<br />TextBox2.Text = xmlnode("value").InnerText<br /><br />Body.Style.Add("background-color", xmlnode("backcolor").InnerText)<br />Dim xmlnode2 As XmlNode = xmlnodelist.Item(1)<br />TextBox2.Text = xmlnode2("value").InnerText<br /><br />End Sub<br /><br />Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click<br /><br />Dim xmlDoc As New XmlDocument<br />xmlDoc.Load(MapPath("text_xml.xml"))<br />Dim xmlnodelist2 As XmlNodeList = xmlDoc.DocumentElement.ChildNodes<br />Dim xmlnode2 As XmlNode = XmlNodeList2.Item(1)<br />TextBox1.Text = xmlnode2("design").InnerText<br />Body.Style.Add("background-color", xmlnode2("backcolor").InnerText)<br />Body.Style.Add("color", "white")<br />End Sub</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-60628588825724183812011-06-09T11:28:00.003+01:002011-06-09T11:30:40.364+01:00XML - Delete All Elements in XML DocumentThe penultamite one today in my tips is how to delete all elements in a XML Document<br /><br />in c# use:<br /><br /><span style="color:#ffff33;">string filename = "categories.xml";<br />XmlDocument xmlDoc = new XmlDocument();<br />xmlDoc.Load(Server.MapPath(filename));<br />XmlNode root = xmlDoc.DocumentElement;<br />XmlNodeList nodes = xmlDoc.SelectNodes("//Category");<br />foreach (XmlNode node in nodes)<br />{<br />node.ParentNode.RemoveChild(node);<br />}<br />xmlDoc.Save(Server.MapPath(filename));<br /></span><br />and in vb.net use:<br /><br /><span style="color:#ffff33;">Dim filename As String = "categories.xml"<br />Dim xmlDoc As XmlDocument = New XmlDocument()<br />xmlDoc.Load(Server.MapPath(filename))<br /><br />Dim root As XmlNode = xmlDoc.DocumentElement<br />Dim nodes As XmlNodeList = xmlDoc.SelectNodes("//Category")<br /><br />For Each node As XmlNode In nodes<br />node.ParentNode.RemoveChild(node)<br />Next<br />xmlDoc.Save(Server.MapPath(filename)) </span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-74449720399630546302011-06-09T11:23:00.002+01:002011-06-09T11:26:48.889+01:00XML - Delete an element by the IDNext step is to delete an element by its ID:<br /><br />in c# use<br /><br /><span style="color:#ffff33;">string filename = "categories.xml";<br />XmlDocument xmlDoc = new XmlDocument();<br />xmlDoc.Load(Server.MapPath(filename));<br />XmlNode root = xmlDoc.DocumentElement;<br />XmlNodeList nodes = xmlDoc.SelectNodes("/CategoryList/Category[@ID='03']");<br />foreach (XmlNode node in nodes)<br />{<br />node.ParentNode.RemoveChild(node);<br />}<br />xmlDoc.Save(Server.MapPath(filename));<br /></span><br />and in vb.net use:<br /><br /><span style="color:#ffff33;">Dim filename As String = "categories.xml"<br />Dim xmlDoc As XmlDocument = New XmlDocument()<br />xmlDoc.Load(Server.MapPath(filename))<br /><br />Dim root As XmlNode = xmlDoc.DocumentElement<br />Dim nodes As XmlNodeList = xmlDoc.SelectNodes("/CategoryList/Category[@ID='03']")<br />For Each node As XmlNode In nodes<br />node.ParentNode.RemoveChild(node)<br />Next<br />xmlDoc.Save(Server.MapPath(filename)) </span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-43945758776416552312011-06-09T11:18:00.002+01:002011-06-09T11:23:05.115+01:00XML - Finding a XML Element by the attribute IDStraight as it sounds, its now time to demonstrate how to find an element by the element's attribute ID.<br /><br />in c#<br /><br /><span style="color:#ffff33;">string filename = "categories.xml";<br />XmlDocument xmlDoc = new XmlDocument();<br />xmlDoc.Load(Server.MapPath(filename));<br /><br />XmlNodeList xnList = xmlDoc.SelectNodes("/CategoryList/Category[@ID='02']");<br />foreach (XmlNode xn in xnList)<br />{<br />Console.WriteLine(xn.InnerText);<br />} </span><br /><br />and in vb.net<br /><br /><span style="color:#ffff33;">Dim filename As String = "categories.xml"<br />Dim xmlDoc As XmlDocument = New XmlDocument()<br />xmlDoc.Load(Server.MapPath(filename))<br /><br />Dim xnList As XmlNodeList = xmlDoc.SelectNodes("/CategoryList/Category[@ID='01']")<br /><br /><br />For Each xn As XmlNode In xnList<br />MsgBox(xn.InnerText)<br />Next</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-7082829066185255732011-06-09T11:14:00.002+01:002011-06-09T11:17:51.380+01:00XML - Amending an Element in a XML DocumentNow we can create and write to a XML Document, we can move onto demonstating how to amend an element in a document.<br /><br />Again, first in c#<br /><br /><span style="color:#ffff33;">string filename = "categories.xml";<br />XmlDocument xmlDoc = new XmlDocument();<br />xmlDoc.Load(Server.MapPath(filename));<br /><br />XmlNode node = xmlDoc.SelectSingleNode("/CategoryList/Category[@ID='03']/MainCategory");<br />//node.Attributes[0].Value = "03";<br /><br />node.Name.ToString();<br />if (node.Name == "MainCategory")<br />{<br />node.InnerXml = "3";<br />}<br /><br />xmlDoc.Save(Server.MapPath(filename));<br /></span><br />and in vb.net<br /><br /><span style="color:#ffff33;">Dim filename As String = "categories.xml"<br />Dim xmlDoc As XmlDocument = New XmlDocument()<br />xmlDoc.Load(Server.MapPath(filename))<br /><br />Dim node As XmlNode = xmlDoc.SelectSingleNode("/CategoryList/Category[@ID='03']/MainCategory")<br /><br />node.Name.ToString()<br />If node.Name = "MainCategory" Then<br />node.InnerXml = "3"<br />End If<br /><br />xmlDoc.Save(Server.MapPath(filename)) </span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-60359112019202782212011-06-09T11:10:00.002+01:002011-06-09T11:13:55.667+01:00XML - Write to an XML DocumnentNext up is a quick bit of coding to show how to dynamically insert a new element to a XML Document.<br /><br />In c# use:<br /><br /><span style="color:#ffff33;">string filename = "categories.xml";<br />XmlDocument xmlDoc = new XmlDocument();<br />xmlDoc.Load(Server.MapPath(filename));<br /><br />XmlNode root = xmlDoc.DocumentElement;<br />XmlElement ListNode = xmlDoc.CreateElement("CategoryList");<br /><br />XmlElement childNode = xmlDoc.CreateElement("MainCategory");<br /><br />XmlElement parentNode = xmlDoc.CreateElement("Category");<br />parentNode.SetAttribute("ID", "04");<br />xmlDoc.DocumentElement.PrependChild(parentNode);<br />// Set attribute name and value!<br /><br />XmlElement mainNode = xmlDoc.CreateElement("MainCategory");<br />XmlElement descNode = xmlDoc.CreateElement("Description");<br />XmlElement activeNode = xmlDoc.CreateElement("Active");<br /><br />// retrieve the text<br />XmlText categoryText = xmlDoc.CreateTextNode(txt_maincategory.Text);<br />XmlText descText = xmlDoc.CreateTextNode(txt_description.Text);<br />XmlText activeText = xmlDoc.CreateTextNode(txt_active.Text);<br /><br />// append the nodes to the parentNode without the value<br />parentNode.AppendChild(mainNode);<br />parentNode.AppendChild(descNode);<br />parentNode.AppendChild(activeNode);<br /><br />// save the value of the fields into the nodes<br />mainNode.AppendChild(categoryText);<br />descNode.AppendChild(descText);<br />activeNode.AppendChild(activeText);<br /><br />xmlDoc.Save(Server.MapPath("categories.xml"));<br /></span><br />and in vb.net<br /><br /><span style="color:#ffff33;">Dim filename As String = "categories.xml"<br />Dim xmlDoc As XmlDocument = New XmlDocument()<br />xmlDoc.Load(Server.MapPath(filename))<br /><br />Dim root As XmlNode = xmlDoc.DocumentElement<br />Dim ListNode As XmlElement = xmlDoc.CreateElement("CategoryList")<br /><br />Dim childNode As XmlElement = xmlDoc.CreateElement("MainCategory")<br />Dim parentNode As XmlElement = xmlDoc.CreateElement("Category")<br />parentNode.SetAttribute("ID", "04")<br />xmlDoc.DocumentElement.PrependChild(parentNode)<br />' Set attribute name and value!<br /><br />Dim mainNode As XmlElement = xmlDoc.CreateElement("MainCategory")<br />Dim descNode As XmlElement = xmlDoc.CreateElement("Description")<br />Dim activeNode As XmlElement = xmlDoc.CreateElement("Active")<br /><br />' retrieve the text<br />Dim categoryText As XmlText = xmlDoc.CreateTextNode(txt_maincategory.Text)<br />Dim descText As XmlText = xmlDoc.CreateTextNode(txt_description.Text)<br />Dim activeText As XmlText = xmlDoc.CreateTextNode(txt_active.Text)<br /><br />' append the nodes to the parentNode without the value<br />parentNode.AppendChild(mainNode)<br />parentNode.AppendChild(descNode)<br />parentNode.AppendChild(activeNode)<br /><br />' save the value of the fields into the nodes<br />mainNode.AppendChild(categoryText)<br />descNode.AppendChild(descText)<br />activeNode.AppendChild(activeText)<br /><br />xmlDoc.Save(Server.MapPath("categories.xml")) </span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-56343259028753575042011-06-09T11:01:00.003+01:002011-06-09T11:09:40.468+01:00XML - Create New XML DocumentThe time of year at looking how XML interacts with c#/vb.net is upon us and its time to start to look at the coding.<br /><br />Now firstly remember to copy these Namespaces at the top of the page where you will write your code.<br /><br />For c# paste in:<br /><br /><span style="color:#ffff33;">using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Web;<br />using System.Web.UI;<br />using System.Web.UI.WebControls;<br />using System.IO;<br />using System.Xml;<br />using System.Xml.Schema;<br />using System.Data;<br /></span><br /><br />and vb.net paste in:<br /><br /><span style="color:#ffff33;">Imports System<br />Imports System.Collections.Generic<br />Imports System.Linq<br />Imports System.Web<br />Imports System.Web.UI<br />Imports System.Web.UI.WebControls<br />Imports System.Xml<br />Imports System.Data<br /></span><br /><br />Now for the code for creating that new XML document from c#/vb.net code:<br /><br />For c# use the following:<br /><br /><span style="color:#ffff33;">XmlDocument xmlDoc = new XmlDocument();<br />XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);<br />// Create the root element<br />XmlElement rootNode = xmlDoc.CreateElement("CategoryList");<br />xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);<br />xmlDoc.AppendChild(rootNode);<br /><br />// Create a new <category>element and add it to the root node<br />XmlElement parentNode = xmlDoc.CreateElement("Category");<br /><br />// Set attribute name and value!<br />parentNode.SetAttribute("ID", "01");<br /><br />xmlDoc.DocumentElement.PrependChild(parentNode);<br /><br />// Create the required nodes<br />XmlElement mainNode = xmlDoc.CreateElement("MainCategory");<br />XmlElement descNode = xmlDoc.CreateElement("Description");<br />XmlElement activeNode = xmlDoc.CreateElement("Active");<br /><br />// retrieve the text<br />XmlText categoryText = xmlDoc.CreateTextNode("XML");<br />XmlText descText = xmlDoc.CreateTextNode("This is a list my XML articles.");<br />XmlText activeText = xmlDoc.CreateTextNode("true");<br /><br />// append the nodes to the parentNode without the value<br />parentNode.AppendChild(mainNode);<br />parentNode.AppendChild(descNode);<br />parentNode.AppendChild(activeNode);<br /><br />// save the value of the fields into the nodes<br />mainNode.AppendChild(categoryText);<br />descNode.AppendChild(descText);<br />activeNode.AppendChild(activeText);<br /><br />xmlDoc.Save(Server.MapPath("categories.xml"));<br /></span><br /><br />and in vb.net use:<br /><br /><span style="color:#ffff33;">Sub create_and_save()<br /><br />Dim xmlDoc As XmlDocument = New XmlDocument<br />Dim xmlDeclaration As XmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "")<br />Dim rootNode As XmlElement = xmlDoc.CreateElement("CategoryList")<br />xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement)<br />xmlDoc.AppendChild(rootNode)<br /><br />'Create a new <category>element and add it to the root node<br />Dim parentNode As XmlElement = xmlDoc.CreateElement("Category")<br /><br />'Set attribute name and value!<br />parentNode.SetAttribute("ID", "01")<br />xmlDoc.DocumentElement.PrependChild(parentNode)<br /><br />'Create the required nodes<br />Dim mainNode As XmlElement = xmlDoc.CreateElement("MainCategory")<br />Dim descNode As XmlElement = xmlDoc.CreateElement("Description")<br />Dim activeNode As XmlElement = xmlDoc.CreateElement("Active")<br /><br /><br />'retrieve the text<br />Dim categoryText As XmlText = xmlDoc.CreateTextNode("XML")<br />Dim descText As XmlText = xmlDoc.CreateTextNode("This is a list my XML articles.")<br />Dim activeText As XmlText = xmlDoc.CreateTextNode("true")<br /><br />'append the nodes to the parentNode without the value<br />parentNode.AppendChild(mainNode)<br />parentNode.AppendChild(descNode)<br />parentNode.AppendChild(activeNode)<br /><br />'save the value of the fields into the nodes<br />mainNode.AppendChild(categoryText)<br />descNode.AppendChild(descText)<br />activeNode.AppendChild(activeText)<br /><br />xmlDoc.Save(Server.MapPath("categories.xml"))<br /></span><br />End SubUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-12929811204501014362011-04-01T10:11:00.004+01:002011-04-01T10:19:32.841+01:00Selected Values for Multiple ListBoxSimple little one in both vb.net and C# When you have a Multiple Selection <span class="blsp-spelling-error" id="SPELLING_ERROR_0">Listbox</span> whether it is static or dynamic and you wish to have previous entered data for a view page to be selected it is imperative that you enter the code for each selection as follows:<p/> in vb.net <p/><span style="color:#ffff00;">lb_cause.Items(1).Selected = True</span> <p/>where 1 is the value for the list item in the <span class="blsp-spelling-error" id="SPELLING_ERROR_1">listbox</span><p/> and c# <span style="color:#ffff00;"><p/>lb_cause.Items[1].Selected = True;</span><p/> Never, ever use lb_cause.<span class="blsp-spelling-error" id="SPELLING_ERROR_2"><p/>SelectedValue</span> = 1 <span class="blsp-spelling-error" id="SPELLING_ERROR_3"><p/>Thats</span> all for now.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-90911248113223027732011-03-23T11:06:00.002+00:002011-03-23T11:14:13.722+00:00Mircosoft ReportViewer with Sub ReportsCreating a report for report viewer and including a sub-report.<br /><br />1. Create a new .ASPX page.<br />2. Go to the Toolbox and double click on Microsoft ReportViewer.<br />3. Right click on the project name in the Solution Explorer and right click.<br />4. Select Add New Item<br />5. Select Data Set and rename the Data Set.<br />6. Click Add<br />7. Click Yes to save the new Data Set in the App_Code folder.<br /><br />In this instance I will be using a Stored Procedure already created.<br /><br />8. Click on Server Explorer in the design view of the Data Set.<br />9. In the Server Explorer Window expand the folders for the database and then the Store Procedure folder to find the stored procedure you wish to use.<br />10.Hold the left button of your mouse down on the stored procedure you wish to use and drag the stored procedure onto the design view of the Data Set.<br />11. Save and close the data set.<br />12. Right click on the project name in the Solution Explorer and right click.<br />13. Select Add New Item<br />14. Select Report and rename the Report.<br />15. Click Add<br />16. Ensure your new report is open.<br />17. Expand Web Site Data Sources<br />18. Expand the Data Set that you created from step 8.<br />19. Drag and drop the field to be displayed in your report on to your report document in design mode.<br />20. Save your report document.<br />21. Go to your .ASPX page created in step 1.<br />22. Click on the arrow to the top right of the ReportViewer.<br />23. Under the drop drown list for choose report, select the report that you have created from step 14.<br />24. Then click on Choose Data Sources from below the drop down list called “Choose Report”<br />25. The Data Set you created in step 8 should automatically be chosen as Report Data Source for the Data Source Instance.<br />26. On the Object Data Source created below the ReportViewer click on the right arrow and select Configure Data Source.<br />27. On the page titled “Choose a Business Object”, the business object should be automatically created. Click Next<br />28. The next page titled “Define Data Methods” you will need to select the method from the drop down list.<br />29. Select the appropriate method and click Next.<br />30. On the page titled “Define Parameters”, you would only need to define a parameter if the SQL statement requires one.<br />31. Input your parameter method if needed.<br />32. ClickFinish<br />33.You can now test this report.<br />34. Now to create a sub report.<br />35. Again you will need a data set for your sub report so repeat steps 3 to 11.<br />36. Now you need to create the report form for your sub-report. For this you need to repeat steps 12 to 19 Only.<br />37. Next right click on the square on the top left axis of where both the axis meets.<br />38. From the context menu select Report Parameters.<br />39. In the Report Parameters wizard. Click add and enter a name in both Name and Prompt in the properties area. I tend to keep these names the same. Make a note of these names for future reference.<br />40. Click OK on the Report Parameters wizard.<br />41. Save and close your new sub report.<br />42. Find and open your original report created between steps 12 to 20.<br />43. Open the toolbox and drag and drop subreport on to your report. Resize the subreport so its shape will be displayed correctly in your report.<br />44. Right click on the grey area of the subreport and click properties in the context menu.<br />45. Under the General tab, find the drop down list subreport and find the name of the report you have created for you subreport and then click on it.<br />46. Then click on the parameters tab.<br />47. Click to the right of the star under the heading Parameter Name and enter the name of the parameter your created in step 39.<br />48. Click then under the heading Parameter Value and select the value you wish to use as a parameter to connect the report to your subreport, for which the subreport will need for its stored procedure.<br />49. Click OK.<br />50. Save and close the report.<br />51. Goto the code page of the ASPX Page you created in step 1. It will end in aspx.vb or aspx.cs dependent on which language you are using. In this case we are using VB.NET so it will be aspx.vb.<br />52. Above the Parital Class of the .aspx.vb document enter the following import commands<br /><br /><span style="color:#ffff33;">Imports Microsoft.Reporting.WebForms<br />Imports System<br />Imports System.Data<br />Imports System.Data.Sql<br />Imports System.Data.SqlClient<br />Imports System.Data.SqlClient.SqlCommand<br /></span><br />53. In the Page Load sub of the .aspx.vb page enter:<br /><br /><span style="color:#ffff33;">AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf ReportViewer1_SubreportProcessing<br /></span><br />Note. ReportViewer1 is the name(ID) of your reportviewer in the HTML code. ReportViewer1_Subreportprocessing is the name of the subroutine in step 54.<br /><br />54. Create the following subroutine.<br /><br /><span style="color:#ffff33;">Public Sub ReportViewer1_SubreportProcessing(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)<br /><br />Dim strParameter1 As String = e.Parameters("<parameter>").Values(0).ToString()<br />Dim rdS As New ReportDataSource("<data>", <subroutine_name>(strParameter1))<br /> e.DataSources.Add(rdS)<br /><br />End Sub<br /></span><br />Note: <parameter> is the name of the parameter you created in step 39.<br /><data> is created from the name of your dataset and the name of your stored proceedure in this fomrat “dataset_storedproceedure”.<br /><subroutine_name> is the name of the subroutine in step 55 used to call the data for the subreport.<br /><br />55. Finally enter the following code for subroutine to open the database to and collect the data for the subreport.<br /><br /><span style="color:#ffff33;">Public Function <subroutine_name> (ByVal strParameter1 As String)<br /> Dim dta As New SqlDataAdapter()<br /> Dim con As New SqlConnection("<data>")<br /> Dim ds As New DataSet()<br /> con.Open()<br /> Dim cmd As New SqlCommand("<sql>", con)<br /> dta.SelectCommand = cmd<br /> dta.SelectCommand.Connection = con<br /> dta.Fill(ds, "subrep_table")<br /> con.Close()<br /> Return ds.Tables("subrep_table ")<br />End Function<br /></span><br />56. Save all document.<br />57. If you now run your report the report will display all data from both the report and the subreport.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-72172502473427345782011-03-16T09:48:00.003+00:002011-03-16T09:51:44.133+00:00Using the IIF command in Microsoft SQL<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXzUOQB0DNNnfZXZZ4q1WpPo1CpRbZPUBwSh-684QNIdSR7WDDu0izKvPXzBvxMLW0Ba-1vy4E7umx4-88QMtJF7XWi5Q4YwBRLQ9rDej2mG3VvERLbYfA6ikcuFpeFqo6x1kOKyZT0yM/s1600/microsoft_Sql.jpg"><img id="BLOGGER_PHOTO_ID_5584612556295905474" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 111px; CURSOR: hand; HEIGHT: 31px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXzUOQB0DNNnfZXZZ4q1WpPo1CpRbZPUBwSh-684QNIdSR7WDDu0izKvPXzBvxMLW0Ba-1vy4E7umx4-88QMtJF7XWi5Q4YwBRLQ9rDej2mG3VvERLbYfA6ikcuFpeFqo6x1kOKyZT0yM/s200/microsoft_Sql.jpg" border="0" /></a><br /><div></div><br /><p>A little nitty problem of today I want to document. Basically came up with this command in an old Access Database</p><p><br /><span style="color:#ffff33;">IIf([Length]=True,"Twelve Months"</span></p><p>Now, there is no IIf command in Microsoft SQL Statments, so this command needs to be converted to :</p><p><br /><span style="color:#ffff33;">CASE<br />WHEN [Length]=1 THEN 'Twelve Months'<br />END</span></p><p>Simple!</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-39930509133863386852011-03-15T15:09:00.003+00:002011-03-15T15:15:13.348+00:00Combine two Columns into one in a Microsoft SQL Statement<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG6VRp4DKKjn7SRXx8mJCZfCP4BscsV5XOLVL9Dyc6H6rmkf6TvDbIQzaZeAtvI5WIbNlVRk7PaLGtPGiEDSbjQnzbaUqoWB05LM25TcSITKsWQ7d0UHWMNjCPwqE_lqFyAEbENZ7SNec/s1600/microsoft_Sql.jpg"><img id="BLOGGER_PHOTO_ID_5584324322004099218" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 111px; CURSOR: hand; HEIGHT: 31px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG6VRp4DKKjn7SRXx8mJCZfCP4BscsV5XOLVL9Dyc6H6rmkf6TvDbIQzaZeAtvI5WIbNlVRk7PaLGtPGiEDSbjQnzbaUqoWB05LM25TcSITKsWQ7d0UHWMNjCPwqE_lqFyAEbENZ7SNec/s200/microsoft_Sql.jpg" border="0" /></a><br /><div>First post of the day, and just a quickie here for a Microsoft SQL Statement. This one is basically for use, if say, you have two fields for example one is first name and the other is last name. This short command in the 'SELECT' section of the SQL statement will condense two fields/columns into one.</div><div></div><div><br /><span style="color:#ffff00;">(RTRIM(forname) + ' ' + RTRIM(lastname)) AS fullname</span></div><div></div><div>There go, short and simple! :)</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-58840777733630185492011-03-14T16:01:00.004+00:002011-03-14T16:14:00.786+00:00Calculations and Formulas with Conditions in Crystal Report<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfurd9KcwnBsWBzWIygIIekje67Cq-_hyphenhyphendsgJfMueaj9GkfiiUsKNE3N0Os-mxkIqE8q0-G29iwIYgm1F0CIWNV9PKMXV1LwMyx3BT9GxtgYCpyc0SkTwyMsaIEf6fqKmCwidsRisCG8o/s1600/crystal-reports-11.jpg"><img id="BLOGGER_PHOTO_ID_5583966983793982818" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 60px; CURSOR: hand; HEIGHT: 43px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfurd9KcwnBsWBzWIygIIekje67Cq-_hyphenhyphendsgJfMueaj9GkfiiUsKNE3N0Os-mxkIqE8q0-G29iwIYgm1F0CIWNV9PKMXV1LwMyx3BT9GxtgYCpyc0SkTwyMsaIEf6fqKmCwidsRisCG8o/s200/crystal-reports-11.jpg" border="0" /></a><br /><div>A short post this time continuing with the Crystal Reports issues. This time I'm going to focus on doing calculations within the formula workshop, in particular with conditional uses.</div><div> </div><div></div><div></div><div><span style="color:#ffff33;">1. From your crystal report, expand Unbound Fields in the Field Explorer.</span></div><div><span style="color:#ffff33;">2. Select Number from Unbound Fields and drag it to the position you require on your Crystal Report.</span></div><div><span style="color:#ffff33;">3. When the Unbound Number has been placed on your report, right click and select 'Edit Formula'.</span></div><div><span style="color:#ffff33;">4. Then follow the code below to create a percentage calculation based on two boolean true/false conditions:</span></div><div><span style="color:#ffff33;"></span></div><div><span style="color:#ffff33;"></span></div><div><span style="color:#ffff33;">Shared numberVar MyCount;</span></div><div><br /><span style="color:#ffff33;">If </span></div><div><span style="color:#ffff33;">{Field 1 Selected from Report Field Window} = true </span></div><div><span style="color:#ffff33;">and</span></div><div><span style="color:#ffff33;">{Field 2 Selected from Report Field Window} = false </span></div><div><span style="color:#ffff33;">then </span></div><div><span style="color:#ffff33;">MyCount := MyCount + 1 </span></div><div><span style="color:#ffff33;">Else </span></div><div><span style="color:#ffff33;">MyCount := MyCount;</span></div><div><br /><span style="color:#ffff33;">MyCount/count({Field 3 Selected from Report Field Window})*100 & '%'</span></div><div></div><div></div><div> </div><div>You can alter this code to your needs but hopefully it will give a broad understanding of a calculation done within Crystal Reports on data already called to the report.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-54140418529795459192011-03-14T11:06:00.007+00:002011-03-14T11:26:38.351+00:00Checkboxes in Crystal Report XI<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6OWxmjgdx5sXrF6aRjkq_JDfIS5m3C9mM7mypifcPQOCnT9bkugo5fvY9amXcFf9PUwA7g5nc0qFnL5M4BSnXa-VAFTd8ePJ3Rn2CVTvYdvWn_R8nzQnvEKdQDMdrMbhjVjPF5RIu0NM/s1600/crystal-reports-11.jpg"><img id="BLOGGER_PHOTO_ID_5583895316505889026" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 43px; CURSOR: hand; HEIGHT: 43px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6OWxmjgdx5sXrF6aRjkq_JDfIS5m3C9mM7mypifcPQOCnT9bkugo5fvY9amXcFf9PUwA7g5nc0qFnL5M4BSnXa-VAFTd8ePJ3Rn2CVTvYdvWn_R8nzQnvEKdQDMdrMbhjVjPF5RIu0NM/s200/crystal-reports-11.jpg" border="0" /></a><br /><div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4gXOTL7luwMQlwTfTLsXib4vKIVCMMToZnJDIn-8wzb7c4MtPUFtkL9Tm4RUhPBY7pt-R1GsMiOAr8Yh1-8gkFDc0AYDAtA0YDuCuuh3ztouEHd4rB6HFWL1C_b_7B066Cyvxa0l25Jk/s1600/crystal-reports-11.jpg"></a><div><div><div>This little problem niggled me for about an hour or so before rendering this soultion below :<br /><br /><span style="color:#ffff33;">1. Left click on the boolean field you wish to change to a checkbox in your Crystal Report.</span><br /><span style="color:#ffff33;">2. Change the font to Wingdings. (This will change your boolean field to a lot of wierd and wonderful characters, but don't worry.</span><br /><span style="color:#ffff33;">3. Right click on the boolean field and select "Format Object".</span><br /><span style="color:#ffff33;">4. Select the common tab.</span><br /><span style="color:#ffff33;">5. Click on the "X+2" button relevant to Display String.</span><br /><span style="color:#ffff33;">6. In the formula box enter the following code :</span><br /><span style="color:#ffff33;"></span><br /><span style="color:#ffff33;">If <field>= true thenCHR(254) else CHR(111)</span><br /><span style="color:#ffff33;"></span><br /><span style="color:#ffff33;">* I find it easier to double click on the boolean to be converted in the Report Field explorer window.</span><br /><span style="color:#ffff33;"></span><br /><span style="color:#ffff33;">7. Save and close your new formula.</span><br /><span style="color:#ffff33;">8. Click 'OK' on the Format Editor.</span><br /><span style="color:#ffff33;">9. When you run your report, you'll find the boolean true/false will be displayed as a checkbox.</span></div></div></div></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-83504814685102424342011-03-08T14:55:00.002+00:002011-03-08T15:00:26.559+00:00How to create a connection from a SQL Database to Crystal Reports with parameters.<br /><br /><br /><span style="color:#ffff33;">1. Create a new Crystal Report<br />2. Set the new Crystal Report as a blank report<br />3. Right click on Database Fields<br />4. Select Database Expert<br />5. Expand Create New Connection<br />6. Double click on OLE DB (ADO)<br />7. Select OLE DB Provider for SQL Server<br />8. Click Next ><br />9. Input name of server<br />10. Input name of database<br />11. Check Integrated Security Checkbox<br />12. Click Next><br />13. On the next page click Finish<br />14. Under Database Expert click on Current Connections<br />15. Click on database name<br />16. Click on dbo or specified user<br />17. Select Table or Stored Procedure<br />18. Table or Stored Procedure will now be available under Database Fields in the report.<br />19. Expand Database Fields<br />20. Expand Table or Stored Procedure<br />21. Select fields from Table or Stored Procedure and drag on to report.<br />22. Save the Crystal Report<br />23. On the web page from toolbox double click on Crystal Report Viewer<br />24. When the grey Crystal Report Viewer box appear click on the right arrow<br />25. Under Choose Report Source select <new><br />26. In the Create Report Source dialog box, under Specify a Crystal Report, select the Crystal Report you wish to display.<br />27. Click OK<br />28. If you do not require parameters debug here otherwise see below for parameters.<br />29. Enter the following code either on Page Load or with a sub/function and include the Import reference at the top of your document.<br /></span><br /><strong><span style="color:#ffff33;">In VB.NET</span></strong><br /><br /><span style="color:#ffff33;">Imports CrystalDecisions.ReportSource<br />Imports CrystalDecisions.Reporting<br />Imports CrystalDecisions.CrystalReports.Engine<br />Imports CrystalDecisions.Shared<br />Dim repDoc As ReportDocument = New ReportDocument<br />Dim repFilePath = Server.MapPath("~\Reports\CrystalReport.rpt")<br />repDoc.Load(repFilePath)<br />repDoc.SetParameterValue(0, <your>)<br />repDoc.SetParameterValue(1, <your>))<br /> <br />CrystalReportViewer1.ReportSource = repDoc<br />CrystalReportViewer1.Visible = True<br /></span><br /><strong><span style="color:#ffff33;">Or in C#<br /></span></strong><br /><span style="color:#ffff33;">using Microsoft.VisualBasic;<br />using System;<br />using System.Collections;<br />using System.Collections.Generic;<br />using System.Data;<br />using System.Diagnostics;<br />using CrystalDecisions.ReportSource;<br />using CrystalDecisions.Reporting;<br />using CrystalDecisions.CrystalReports.Engine;<br />using CrystalDecisions.Shared;</span><br /><br /><span style="color:#ffff33;">ReportDocument repDoc = new ReportDocument();<br />dynamic repFilePath = Server.MapPath("~\\Reports\\CrystalReport.rpt");<br />repDoc.Load(repFilePath);<br />repDoc.SetParameterValue(0, <your>);<br />repDoc.SetParameterValue(1, <your>);<br />CrystalReportViewer1.ReportSource = repDoc;<br />CrystalReportViewer1.Visible = true;</span><br /><br /><span style="color:#ffff33;">30. The report is now ready for display, and can be tested using the debugger.</span><br /><span style="color:#ffff33;"></span><br /><span style="color:#000000;">That's how to basically use parameters on a Crystal Report using Visual Studio 2008 with ASP.NET 3.5.</span><br /><br />Next will be how to use subGroups within a Crystal ReportUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-29718991287658274072011-03-08T12:53:00.004+00:002011-03-08T13:00:15.499+00:00Crystal Reports - The BasicHello, today I'm going to display how to create a basic Crystal Report by directly accessing a table or a stored procedure from a database.<br /><br /><span style="color:#ffff33;">1. Create a new Crystal Report<br />2. Set the new Crystal Report as a blank report<br />3. Right click on Database Fields<br />4. Select Database Expert<br />5. Expand Create New Connection<br />6. Double click on OLE DB (ADO)<br />7. Select OLE DB Provider for SQL Server<br />8. Click Next ><br />9. Input name of server<br />10. Input name of database<br />11. Check Integrated Security Checkbox<br />12. Click Next><br />13. On the next page click Finish<br />14. Under Database Expert click on Current Connections<br />15. Click on database name<br />16. Click on dbo or specified user<br />17. Select Table or Stored Procedure<br />18. Table or Stored Procedure will now be available under Database Fields in the report.<br />19. Expand Database Fields<br />20. Expand Table or Stored Procedure<br />21. Select fields from Table or Stored Procedure and drag on to report.<br />22. Save the Crystal Report<br />23. On the web page from toolbox double click on Crystal Report Viewer<br />24. When the grey Crystal Report Viewer box appear click on the right arrow<br />25. Under Choose Report Source select <new><br />26. In the Create Report Source dialog box, under Specify a Crystal Report, select the Crystal Report you wish to display.<br />27. Click OK<br />28. The report is now ready for display, and can be tested using the debugger.<br /></span><br />Later I will show how to use integer and sub groups within a crystal report.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-42458225828260019762010-08-13T14:43:00.004+01:002010-08-13T14:48:23.445+01:00Being my first entry for over a week and also my first since returning from holiday, I'd though I would do a nice and easy one on this Friday afternoon and demonstrate the switch and case statement in VB.Net and C#....<br /><br />Firstly, it is important to remember that the case identities correspond to the value's given from the drop down menu or listbox etc....<br /><br />Ok the code for use in VB.Net is....<br /><br /><span style="color:#ffff00;">Select Case ListBox1.SelectedValue<br /><br />Case 1<br />MsgBox("hello")<br />Case 2<br />MsgBox("thanks")<br />Case 3<br />MsgBox("bye")<br />End Select</span><br /><br />and for C# it's...<br /><br /><span style="color:#ffff00;">switch (DropDownList1.SelectedValue) </span><br /><span style="color:#ffff00;"></span><br /><span style="color:#ffff00;">{ case "1": </span><br /><span style="color:#ffff00;">MessageBox.Show("hello"); </span><br /><span style="color:#ffff00;">break;<br />case "2": </span><br /><span style="color:#ffff00;">MessageBox.Show("thanks"); </span><br /><span style="color:#ffff00;">break;<br />case "3": </span><br /><span style="color:#ffff00;">MessageBox.Show("bye");</span><br /><span style="color:#ffff00;">break;}</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-71912922354958199652010-08-03T16:10:00.003+01:002010-08-03T16:16:06.404+01:00How to Capitalize the First Letter of Every Word in a StringNeat little bit of coding to help anyone capitalize or make upper case the first letter of every word in a string. Quite handy this little script as first it will make sure that all letters in the string are formatted correctly...<br /><br />So in VB.Net we have :<br /><br />in the page load<br /><br /><span style="color:#ffff33;">Dim <span class="blsp-spelling-error" id="SPELLING_ERROR_0">objconvertText</span> As <span class="blsp-spelling-error" id="SPELLING_ERROR_1">convertText</span> </span><br /><span style="color:#ffff33;"><span class="blsp-spelling-error" id="SPELLING_ERROR_2">objconvertText</span> = New <span class="blsp-spelling-error" id="SPELLING_ERROR_3">convertText</span> </span><br /><span style="color:#ffff33;"><span class="blsp-spelling-error" id="SPELLING_ERROR_4">MsgBox</span>(<span class="blsp-spelling-error" id="SPELLING_ERROR_5">objconvertText</span>.convert("CAPITALIZE THIS!"))</span><br /><br />and for the class<br /><br /><span style="color:#ffff00;">Public Function convert(<span class="blsp-spelling-error" id="SPELLING_ERROR_6">ByVal</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_7">theWord</span> As String) </span><br /><span style="color:#ffff00;">Dim <span class="blsp-spelling-error" id="SPELLING_ERROR_8">capitalWord</span> </span><br /><span style="color:#ffff00;"><span class="blsp-spelling-error" id="SPELLING_ERROR_9">capitalWord</span> = <span class="blsp-spelling-error" id="SPELLING_ERROR_10">LCase</span>(<span class="blsp-spelling-error" id="SPELLING_ERROR_11">theWord</span>) </span><br /><span style="color:#ffff00;"><span class="blsp-spelling-error" id="SPELLING_ERROR_12">capitalWord</span> = <span class="blsp-spelling-error" id="SPELLING_ERROR_13">StrConv</span>(<span class="blsp-spelling-error" id="SPELLING_ERROR_14">capitalWord</span>, <span class="blsp-spelling-error" id="SPELLING_ERROR_15">VbStrConv</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_16">ProperCase</span>) </span><br /><span style="color:#ffff00;">Return <span class="blsp-spelling-error" id="SPELLING_ERROR_17">capitalWord</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_18">ToString</span> </span><br /><span style="color:#ffff00;">End Function</span><br /><br /><strong>and the same in C# is in the page load</strong>:<br /><br /><span style="color:#ffff00;">MessageBox.Show(convertTextFirst.capitalText("CAPITALIZE THIS!"));</span><br /><br />and then in a class :<br /><br /><span style="color:#ffff00;">public static string <span class="blsp-spelling-error" id="SPELLING_ERROR_19">capitalText</span>(string <span class="blsp-spelling-error" id="SPELLING_ERROR_20">theWord</span>) </span><br /><span style="color:#ffff00;">{string <span class="blsp-spelling-error" id="SPELLING_ERROR_21">capitalWord</span>;</span><br /><span style="color:#ffff00;"><span class="blsp-spelling-error" id="SPELLING_ERROR_22">capitalWord</span>= <span class="blsp-spelling-error" id="SPELLING_ERROR_23">theWord</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_24">ToLower</span>();</span><br /><span style="color:#ffff00;"><span class="blsp-spelling-error" id="SPELLING_ERROR_25">capitalWord</span> = char.<span class="blsp-spelling-error" id="SPELLING_ERROR_26">ToUpper</span>(<span class="blsp-spelling-error" id="SPELLING_ERROR_27">capitalWord</span>[0]) + <span class="blsp-spelling-error" id="SPELLING_ERROR_28">capitalWord</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_29">Substring</span>(1); </span><br /><span style="color:#ffff00;">return <span class="blsp-spelling-error" id="SPELLING_ERROR_30">capitalWord</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_31">ToString</span>(); }</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3857813572497980031.post-64660337967529587132010-08-03T15:56:00.005+01:002010-08-03T16:10:11.739+01:00Calculating the Length of a String<span style="font-family:verdana;">Simple little one again for a Tuesday afternoon. A quick little demonstration on how to calculate the length of a string :<br /><br /><span style="color:#ffff66;"><span style="color:#ffffff;">in c#</span><br /><br /></span><span style="color:#ffff33;">string test_string;<br />int value;<br />test_string = "George";<br />value = test_string.Length;<br />length.Text = value.ToString();<br /></span><br />and also in vb.net<br /><br /><span style="color:#ffff00;">Dim test_string As String<br />Dim value As Integer<br />test_string = "George"<br />value = Len(test_string)<br />length.Text = value</span><br /><br />and finally in PHP:<br /><br /><span style="color:#ffff00;">$howlong="how long is my string including spaces";<br />echo "The length of the string is : ".strlen($howlong);</span></span>Unknownnoreply@blogger.com0