Monday, October 18, 2010

Sql Server Manangement Studio Table Modify Error

While altering table on Sql Server Management studio sometimes we get an error like this :




This due to a setting in Management Studio.

Just go to Tools -> Options->Designer->Table and Database Desginers and uncheck

"Prevent Saving changes that require table re-creation"





Wednesday, October 13, 2010

What are the RowTypes supported by GridView ?

DataRow ,
Header ,
Footer,
EmptyDataRow,
Pager,
Separator


1. What is the difference between RowCreated and RowDataBound ?

The Bound Cell Data is not available in RowCreated event.

Otherwise there all the things which can be done in RowDataBound
can also be done in RowCreated ( things which do not involve bound data).

Other difference is RowCreated is automatically called in
Postback and Nonpostback scenarios. RowDataBound is called when a
call to DataBind is given.


2. What is RowCommand ?
This is an event fired when command button is clicked on Gridview.
The command button can be one of the system types (delete, edit, update,..)
or custom command type.

GridView_Sorting or GridView_Sorted

Which event of GridView will you implement for sorting ?

-> Sorting

GridView_Sorting or GridView_Sorted ?

-> Sorting ?


Which event of GridView will you implement for paging ?

->PageIndexChanging

PageIndexChanging or PageIndexChanged ?

->PageIndexchanging

PageIndexChanging , PageIndexChanged , Sorting , Sorted, which ones
are frequently required and why ?

PageIndexChaning and Sorting are frequently required.

'ed' events are not always required, they are required
only when customization to data is required after
page is changed or sorted.

What values are supported for a DataColumn's MappingType ?

Element (The column is mapped to an XML element. )
Attribute (The column is mapped to an XML attribute. )
SimpleContent (The column is mapped to an XmlText node. )
Hidden (The column is mapped to an internal structure. )

DataColumn : Default Value and Expression

DataColumn has five constructors, each with one or more of
following parameters :

Public Sub New ( _
columnName As String, _
dataType As Type, _
expr As String, _
type As MappingType _
)

I was thinking that the third parameter is the default value
which will be assigned to the column.

e.g. If I create a column like following and add it to the table :
dt.Columns.Add(New DataColumn("IsItAStop", System.Type.GetType("System.Boolean"), "False"))

I expected that the Boolean column will be added and will have a default
value of "False", which obviuosly I will be able to change
while adding a new row to the table.



Dim dtdtdr As DataRow = dt.NewRow
Dim ck1 As CheckBox = CType(grrow.Cells(2).FindControl("test"), CheckBox)
If Not ck1 Is Nothing Then
If ck1.Checked = True Then
dtdtdr("IsItAStop") = "True"
End If
End If
dt.Rows.Add(dtdtdr)


Now I expected the column value to be "True" for the new row added.

On the contrary, I found that the value after dt.Rows.Add was always "False".

The reason was that the "expr" in the DataColumn ctor is an expression,
and not default value.

The expression is always evaluated on call to Rows.Add. The basic
purpose of this expression is for creating derived columns.

To set a default value,
use the DefaultValue property of DataColumn.




col = New DataColumn("IsItAStop", System.Type.GetType("System.Boolean"))
col.DefaultValue = "False"
dt.Columns.Add(col)

Tuesday, October 12, 2010

Sysindex ( How Do I Display List of Rows In Tables In A Database)

Sysindexes table is an interesting table which stores important metadata.

Need to have a detail look into it.

By the way here is some code which uses sysindex to display
number of columns in all tables in a database :


CREATE PROCEDURE [dbo].[DisplayRowCount] as
BEGIN
declare @tabcnt int
declare @printline char (60)
select @tabcnt = count (*) from sysobjects where type = 'U'


If @tabcnt != 0
BEGIN
select "TABLE NAME"= convert (varchar (50), o.name), ROWS=i.rows
from sysobjects o, sysindexes i
where o.type = 'U'
and o.id = i.id
and i.indid in (0,1)
order by o.name
END

select @printline = '(' + convert (varchar(10), @tabcnt) +
' tables in ' + DB_NAME() + ')'

print @printline

END

Friday, October 8, 2010

Database Restore and Backup using Queries

backup database bnsdavgps to disk = 'D:\MS SQL Databases\Data\bnsdavgps.bak'

RESTORE FILELISTONLY FROM DISK = 'D:\MS SQL Databases\Data\bnsdavgps.bak'
--GpsMelissaDPS
--GpsMelissaDPS_log

RESTORE DATABASE BNSDAVGPSNew FROM DISK = 'D:\MS SQL Databases\Data\bnsdavgps.bak'
WITH REPLACE, File=1, Norecovery,
MOVE 'GpsMelissaDPS' TO 'D:\MS SQL Databases\Data\bnsdavgpsnew.mdf',
MOVE 'GpsMelissaDPS_log' TO 'D:\MS SQL Databases\Data\bnsdavgpsnew_log.ldf'

Loop Engineering: Designing the Systems That Prompt Your Agents

Loop Engineering For the last couple of years, the core skill in working with AI was writing a good prompt. You'd craft careful instru...