Monday, January 29, 2007

script to list out all of the primary key to foreign key relationships

script for SQL Server 2000 that lists out all of the primary key to foreign key relationships by Micheal Imhoff.

http://michael.omnicypher.com/2007/01/foreign-key-information.html

select
pk_tbl.name as PRIMARY_KEY_TABLE
,pk_col.name as PRIMARY_KEY_COLUMN
,t_obj.name as FOREIGN_KEY_TABLE
,col.name as FOREIGN_KEY_COLUMN
,c_obj.name as CONSTRAINT_NAME
from
sysobjects c_obj
,sysobjects t_obj
,syscolumns col
,sysreferences ref
,sysobjects pk_tbl
,syscolumns pk_col
where
permissions(t_obj.id) != 0
and c_obj.xtype in ('F ')
and t_obj.id = c_obj.parent_obj
and t_obj.id = col.id
and col.colid in
(ref.fkey1,ref.fkey2,ref.fkey3,ref.fkey4,ref.fkey5,ref.fkey6,
ref.fkey7,ref.fkey8,ref.fkey9,ref.fkey10,ref.fkey11,ref.fkey12,
ref.fkey13,ref.fkey14,ref.fkey15,ref.fkey16)
and c_obj.id = ref.constid
and pk_tbl.id = ref.rkeyid
and pk_col.id = pk_tbl.id
and pk_col.colid = ref.rkey1
order by
pk_tbl.name, pk_col.name

Wednesday, December 27, 2006

Using Javascript in aspx page

To use javascript in aspx page for functions like window popup etc...
1)In aspx page html view write the necessary javascript:-

function OpenNew(message){ window.open("NewPage.aspx?" + message,"_blank"); }

2)In code behind write function to register page script ex.

protected void RegisterSubmitErrorScript(string Message) { string script = "< script language="'j a v a s c r i p t '">OpenNew('" + Message + "');"; Page.RegisterStartupScript("OpenNew",script);
}
3)Then anywhere in the page when u want to respond for new window to be open based on any condition being true or false call function above passing parameters if any ex.
RegisterSubmitErrorScript("param1=" + param);

Note:By changing javascript function "window.open" with any of other javascript functions,they can be performed.

Friday, December 15, 2006

ASP.NET DropDown -Selection

To change the selected index of a dropdown list already populated if Value or text is known

myDropDown.SelectedIndex = myDropDown.Items.IndexOf(myDropDown.items.findbytext(strCurrentState))

myDropDown.SelectedIndex = myDropDown.Items.IndexOf(myDropDown.items.findbyvalue(strCurrentState))

ASP.NET DataGrid ItemDataBound Facts

--To Access a ROW OR RECORD IN DATAGRID

--during item databound event--

->when using a DataReader
DbDataRecord rv=(DbDataRecord)e.Item.DataItem;
To check if column is null or not
--if(!rv.isDBNull(2)) 2->column index
To get value of paticular column
--rv.GetValue(2)

->when using a DataSet
DataRowView rv=(DataRowView)e.Item.DataItem;
To check if column is null or not
-- if (!rv.Row.IsNull(2)) 2->column index
To get value of paticular column
--rv.Row.ItemArray.GetValue(1)

--to find control in datagrid and change/modify its property ex Label
in item databound value
Label lblType=new Label();
check if datarow or datarecord "not null" as shown above
then lblType=(Label)e.Item.FindControl("lblID"); where lblID->id of control

once we have control can easily modify property,
ex lblType.visible=false;