Sunday, March 7, 2010

DataBase Specific Queries

Hello friends
Here are few Database Specific Queries
  • Select All Database list 
1: SELECT [name] FROM sys.databases
2: SELECT [name] FROM sys.sysdatabases
This will Result
Select All Database list


  • Select All Tables of particular Database. 
1: SELECT Name, type,type_desc FROM sys.objects 
2: where Type='u'
This will Result
Select All Tables of particular Database
  • Here Fields Type and Type_Desc are
Type Type_Desc
C CHECK_CONSTRAINT
D DEFAULT_CONSTRAINT
F FOREIGN_KEY_CONSTRAINT
FN SQL_SCALAR_FUNCTION
IF SQL_INLINE_TABLE_VALUED_FUNCTION
IT INTERNAL_TABLE
P SQL_STORED_PROCEDURE
PK PRIMARY_KEY_CONSTRAINT
S SYSTEM_TABLE
SQ SERVICE_QUEUE
TF SQL_TABLE_VALUED_FUNCTION
TR SQL_TRIGGER
U USER_TABLE
UQ UNIQUE_CONSTRAINT
V VIEW
can be more than this…
  • Select Columns from particular Table
1: SELECT column_name as [Column Name],data_type as [Data Type],Character_maximum_length as [Character Maximum Length]
2: FROM information_schema.columns
3: WHERE table_name = 'table_1'
This will Result

Select Columns from particular Table
 
All The Best

Friday, March 5, 2010

RemoteDataPass- pass data from one page to Remote Page

As i Committed in my previous post, that i will post code for ReportDataPass.

it is Quite difficult to pass Data from one Application to another application,
because here Cookie, Session variable will not help.
now a very simple way it Query string,  But as our previous condition, we don’t want to use Query string.
so the last way..
Post Method
as we know, in any server side scripting languages, like asp, jsp, PHP.. on submit button, the Data is posted to another page or to itself.
and using Request[“Filedname”]
we can have its Value. the same logic we are going to apply..
but as we are using VS, where we have facilities of Masterpages and Content page,so when we are using any ContentPage, in that case we can not have form and its Post method.

So we are going to make a dynamic Html Page, and  using dynamic Javascript we will post Data to another page.

So create a Class like this
   1: public class RemoteDataPass
   2: {
   3:     
   4:     private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
   5:     public string PostUrl = "";
   6:     public void Add(string FieldName, string Fieldvalue)
   7:     {
   8:         Inputs.Add(FieldName, Fieldvalue);
   9:     }
  10:  
  11:     public void Post()
  12:     {
  13:         System.Web.HttpContext.Current.Response.Clear();
  14:         System.Web.HttpContext.Current.Response.Write("<html><head></head><body onload=\"document.form1.submit()\">");
  15:         System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"form1\" method=\"post\" action=\"{0}\" >", PostUrl));
  16:         for (int i = 0; i < Inputs.Keys.Count; i++)
  17:         {
  18:             System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
  19:         }
  20:         System.Web.HttpContext.Current.Response.Write("</form></body></html>");        
  21:         System.Web.HttpContext.Current.Response.End();
  22:     }
  23: }








now to post Data from our Source Page.



   1: RemoteDataPass RemotePost = new RemoteDataPass();
   2:         RemotePost.PostUrl = "http://ransandeep.blogspot.com/test.aspx";
   3:         RemotePost.Add("FirstField", "Sandeep");        
   4:         RemotePost.Post(); 










now at Receiving page



   1: protected void Page_Load(object sender, EventArgs e)
   2:    {
   3:         if (Request.Form[ "FirstField" ] != null  )
   4:         {
   5:            Response.Write( "FirstField : "  + Request.Form[ "FirstField" ] +  "</br>" ) ;
   6:         }         
   7:    }







So this is Simple after getting know….





All the best..

Popup new Window by Javascript

A very Common trick
Open a new window as Popup by javascript…
Clicking on any Server Button

   1: <asp:Button ID="Button1" 
   2:                 runat="server" 
   3:                 OnClientClick="window.open('Page2.aspx',null,'height=200,width=400
   4:                         ,status=yes,toolbar=no,menubar=no,location=no,scroll=no');
   5:                         return false;"
   6:                 Text="Button" />







All The Best..