TechTips .NET/ CSLA.NET / ASP.NET / VB.NET / C# / SQL Server / MySql / Android
  • Oct
    12

     

    Hi friends.. sometime back I had a discussion with few of my friends on different topics on OOPS. Just thought to put a post of some of the important facts which might help others as well.  Starting with Abstract classes. Will be writing on more topics in next posts.
    Abstract Classes

    1. Abstract classes can have a non abstract ctor and they can’t be instantiated.
    2. Since abstract classes can’t be instantiated one should not use Public and Protected Internal modifier with Abstract class Ctor.
    3. Abstract class can be derived from a concrete class.
    4. Abstract class can have non abstract members (methods, events, properties) but non abstract class can’t have abstract members.
    5. An abstract class may contain abstract methods and accessors.
    6. An abstract method is implicitly a virtual method.
    7. Static and Virtual modifiers can’t be used with abstract methods
    8. An abstract inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.
    9. Abstract classes can have concrete static methods.

    Hope this helps..Please put your comments and any additional info about abstract class which may help others as well.

    No Comments
  • May
    29

    Restored blog..

    Filed under: General;

    Guys..

    I have recently changed my host and blog was up and down for last few days. Its back now however. I shall be posting new articles shortly..

    Thanks for bearing..

    Kshitij

    No Comments
  • Jan
    17


    So what is the difference between CONST and READONLY? Let’s examine the difference between these two with an example.


    So we can clearly see that we can initialize readonly variables during the declaration and in the constructor of the class. So its possible to initialize readonly variables once at run time but we can’t change value of const variables.

    Happy coding!

    7 Comments
  • Jan
    10

    Hi All,

    Just started development on android and published my first application on Android App store :) . It’s simple but good one to start with. You guys can check this out at market://search?q=pname:decode.android.speedway
    from your android mobile.

    No Comments
  • Aug
    23

    Hi,

    Recently I need to show multi-line string in a datagridview cell. To achieve that we need to write code in CellFormatting event of DataGridview. Following is the code

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (e.Value.Equals("Error"))
                {
                    e.CellStyle.BackColor = Color.Red;
                    e.CellStyle.ForeColor = Color.White;
    
                }
                else
                {
                    if ((!e.Value.Equals("OK")) && e.ColumnIndex==2)
                    {
                        e.CellStyle.BackColor = Color.Green;
                        e.CellStyle.ForeColor = Color.White;
                        e.CellStyle.WrapMode = DataGridViewTriState.True;
                        dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
    
                    }
    
                }
            }
    

    I hope this help!

    Kshitij

    3 Comments
  • Dec
    8

    Hi,

    Few days back i needed a code snippet to write a text in starting of all files in a directory. Searched net but could not find any working code. Then i decide to write my own code and come up with following code.

    I hope this will help guys who are looking to do same.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace AddTextToFiles
    {
        class Program
        {
            private static DirectoryInfo ds;
            static void Main(string[] args)
            {
                Console.WriteLine("*********************Written By Kshitij Sharma ***********************");
                Console.WriteLine("Please Enter the path and Press enter ");
                string sPath = Console.ReadLine();
                Console.WriteLine("Please Enter <B style="BACKGROUND-COLOR: #a0ffff; COLOR: black">Text</B> ");
                string sText = Console.ReadLine();
                addText(sPath,sText);
                Console.WriteLine("*****************Reach Me @ k.sharma78@gmail.com****************");
                Console.Read();
            }
    
            private static void addText(string pth,string txt)
            {
                try
                {
    
                    if (!string.IsNullOrEmpty(pth))
                    {
                        ds = new DirectoryInfo(pth);
                    }
                    else
                    {
                        ds = new DirectoryInfo("c:\\testfiles");
                    }
                    if (string.IsNullOrEmpty(txt))
                    {
                        txt = "<!--#Include File=\"CheckSQL.inc\"-->";
                    }
                    foreach (FileInfo f in ds.GetFiles("*.asp"))
                    {
                        Console.WriteLine("Writing to file-->" + f.Name);
                        string strPath = ds.Root + ds.Name + "\\" + f.Name;
                        StreamReader sr = new StreamReader(strPath);
                        string fileContent = sr.ReadToEnd();
                        sr.Close();
                        StreamWriter sw = new StreamWriter(strPath, false);
                        StringReader gr = new StringReader(fileContent);
                        sw.WriteLine(txt);
                        sw.WriteLine(gr.ReadToEnd());
                        sw.Close();
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.Read();
                }
            }
        }
    }
    
    2 Comments
  • Dec
    8

    Restored Blog

    Filed under: General;

    Hi,

    It seems that the hosting server of my website was hacked and all data was removed from the database.
    I have restored website from an earlier backup i have. It seems that we lost some of the Posts.

    I will try to restore all posts soon.

    Thanks

    2 Comments
  • Jun
    16


    So what basically is reflection:


    Using a class library methods at runtime without adding its reference in your project is done through Reflection. In this article I will show you how to use reflection using a simple example.
    Let’s first create a Class Library.

    ScreenHunter_01 Jun. 13 12.06

    let’s code our ReflectionTest Class

    
    Namespace reflectionclass
    Public Class ClsReflection
    
    #Region "Methods"
    Public Function add(ByVal x As Integer, ByVal y As Integer) As Integer
    Return x + y
    End Function
    
    Public Function [sub](ByVal x As Integer, ByVal y As Integer) As Integer
    Return x - y
    End Function
    #End Region
    
    End Class
    End Namespace
    

    let’s make a test project now. Add a windows form application to the solution.

    ScreenHunter_02 Jun. 13 12.20

    Now let’s design our Form.

    ScreenHunter_02 Jun. 16 12.48

    so after putting two command buttons two listview controls and four textbox controls our form should look like this.

    Let’s code our form now

    Imports System.Reflection
    
    Public Class Form1
    Dim objAssembly As Assembly
    'Declare an array of Types to Hold All Classes of Assembly
    Dim arrTypes As Type()
    Dim objType As Type
    'Delcare an array to hold all methods of Assembly
    Dim arrMethods As MethodInfo()
    Dim objMethod As MethodInfo
    
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Try
    OpenFileDialog1.ShowDialog()
    txtAssembly.Text = OpenFileDialog1.FileName
    objAssembly = System.Reflection.Assembly.LoadFrom(txtAssembly.Text)
    For Each cls In objAssembly.GetTypes
    '
    If cls.FullName.IndexOf("ClsReflection") > 0 Then
    lstClasses.Items.Add(cls.FullName)
    End If
    Next
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub
    
    Private Sub lstClasses_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstClasses.SelectedIndexChanged
    Try
    lstMethods.Items.Clear()
    objType = objAssembly.GetType(Me.lstClasses.SelectedItem.ToString)
    arrMethods = objType.GetMethods
    For Each method In objType.GetMethods
    lstMethods.Items.Add(method.Name)
    Next
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub
    
    Private Sub cmdCallMethod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCallMethod.Click
    Try
    objMethod = objType.GetMethod(lstMethods.SelectedItem.ToString())
    Dim obj As Object
    obj = Activator.CreateInstance(objType)
    'Let's Create Array of Parameter
    Dim objParameters As Object() = {Int32.Parse(txtNum1.Text), Int32.Parse(txtNum2.Text)}
    'If there is no parameter in method then on the place of oo pass the null
    txtResult.Text = objMethod.Invoke(obj, objParameters).ToString()
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub
    End Class
    

    ScreenHunter_03 Jun. 16 13.09

    Select Add and put any two numbers in the first and second number textbox and click on execute method and you should get the result.

    ScreenHunter_04 Jun. 16 13.12

    Now select Sub and enter any two number in first number and second number textbox and press execute method and you should get the desired result.

    This article show you how you can call method dynamically at runtime without referencing the assembly in your project. It is a very basic example but I think it will help you to understand how reflection works in .Net.

    If you have any point you are not getting in this article please let me know i will try to explain.

    Happy Coding!

    Kshitij

    6 Comments
  • Jun
    9


    So what exactly Stored Procedures are :

    • Basically in a database management system (DBMS), a stored procedure is a set of Structured Query Language (SQL) statements with an assigned name that’s stored in the database in compiled form so that it can be shared by a number of programs. The use of stored procedures can be helpful in controlling access to data (end-users may enter or change data but do not write procedures), preserving data integrity (information is entered in a consistent manner), and improving productivity (statements in a stored procedure only need to be written one time). Stored procedures have been part of Oracle, MS SQL Server, DB-2, postgreSQL and others for years but MySQL introduce Store procedures recently in version 5.xxx. MySQL stored procedures are very similar to the DB2 implementation, as both are based on the SQL:2003 standard.

    Read the rest of this entry »

    25 Comments
  • Jun
    5

    Recently i faced lots of problem with my hosting company as almost daily my site was down due to some problems in their servers. They usually send me a link to trace my site. Basically that site provide service to ping back any URL from their servers which are located in different countries. So it is like first their US server pings the URL and sends back the results weather site is responding or not and then all of the servers located in different part of the word do the same thing and finally giving a summery. For me it was annoying to go again and again to that site and then type URL to trace it back. Furthermore they charge for their services if you wants to check your site (or any other URL) 24×7. So i decided to write my own service. In this service i write the ping back results to windows log but you can always enhance this code to send mails or even SMS if your site is down.

    So lets start and create a Windows Web Service Project

    New_prj_WinService
    Read the rest of this entry »

    8 Comments

Translate

EnglishFrenchGermanHindiItalianPortugueseRussianSpanish
| More