Friday, 9 November 2012

how to get the count of columns of tables in sql



Get the number of columns in the table

Use [yourdatabaseName]

SELECT COUNT(*)
FROM information_schema.columns
WHERE table_name = 'yourtableName'

OR

SELECT COUNT(*)
FROM yourdatabaseName.sys.columns
WHERE object_id = OBJECT_ID('yourdatabaseName.dbo.yourtableName')

Saturday, 10 December 2011

Boxing and Unboxing

Boxing is the process of converting a value type to the type object.
e.g

int i = 123;
object o = (object)i; // boxing

Unboxing extracts the value type from the object.
o = 123;
i = (int)o; // unboxing

Tuesday, 1 November 2011

Login Code in ASP.Net using C#

using DataReader :

Sqlconnection con = new sqlconnection("your conectionstring");

Sqlcommand cmd = new sqlcommand();

cmd.commandtext = "select * from table";

cmd.connection = con;

if (con.state==connectionstate.closed) con.open();

SqlDatareader dr = cmd.executereader();

while(dr.read)

{

       if ( dr["Username"] == textbox1.text.trim() && dr["Password"] == textbox2.text )

       {

                 response.redirect("Homepage.aspx");

               return;

        }

}