Monday, December 19, 2011

Change GridView Column HeaderText programmatically

Actually it does not work on PreRender event, so you have to do it in the RowCreated event:

 

protected void GridViewLot_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                               if (!string.IsNullOrEmpty(lt.CustomAttributeName1)) e.Row.Cells[5].Text = lt.CustomAttributeName1; else e.Row.GridView.Columns[5].Visible = false;
                       }

}

Wednesday, December 15, 2010

Native MD5 in SQLServer

Starting from SQL Server 2005, you can now compute some hash in your sql queries or stored procedures:



HashBytes ( '<algorithm>', { @input | 'input' } )
<algorithm>::= MD2 | MD4 | MD5 | SHA | SHA1
 
Example
DECLARE @HashThis nvarchar(4000);
SELECT @HashThis = CONVERT(nvarchar(4000),'dslfdkjLK85kldhnv$n000#knf');
SELECT HashBytes('SHA1', @HashThis);
GO
source: 
http://msdn.microsoft.com/en-us/library/ms174415.aspx

Saturday, August 14, 2010

TotalRecall Google Chrome Extension 1.02 Fix

TotalRecall is a cool google Chrome extension that allow you to save the content of online forms, it’s very usefull for developper :-)

Sadly the extension is not working anymore with the latest google chrome release. After some investigation, I’ve found that it fail because of a breaking change in google Chrome database API…

In the background html, I’ve made the following changes – in bold :

db:        null,
  dbName:    "totalrecall",
  dbVersion: '2.0',

  // this creates the database if it doesn't already exist
  databaseConnect: function()
  {
    bgNs.db = openDatabase(bgNs.dbName, bgNs.dbVersion, 'Forms database', 1024*1024*3);
  },


I've repack the extension with the fix: here you can download.

Thursday, August 12, 2010

SQL – Get the list of columns of a table

This can be done by querying the system tables of SQLServer

 

SELECT   
SysObjects.[Name] as TableName,
SysColumns.[Name] as ColumnName,
SysTypes.[Name] As DataType,
SysColumns.[Length] As Length
FROM
SysObjects INNER JOIN SysColumns
ON SysObjects.[Id] = SysColumns.[Id]
INNER JOIN SysTypes
ON SysTypes.[xtype] = SysColumns.[xtype]
WHERE SysObjects.[type] = 'U'

and SysColumns.[Name] like '%mytable%'

ORDER BY SysObjects.[Name]

SQL Server: how to find view or stored procedure with specific text

You can query the system tables:

SELECT [name]
FROM [dbo].[sysobjects] obj
INNER JOIN [dbo].[syscomments] cmt
ON obj.[id] = cmt.[id]
where cmt.[text] like '%my text%'

Sunday, August 08, 2010

How to get database list in c#

It can be done easily with the GetSchema method on a SqlConnection instance:

 

protected string ServerConnectionString
{
get
{
return "Data Source=(local)\\SQLEXPRESS;;Integrated Security=SSPI;";
}
}
protected string[] GetDatabaseList()
{
List<string> databases = new List<string>();
using (SqlConnection sqlConx = new SqlConnection(ServerConnectionString))
{
sqlConx.Open();
DataTable tblDatabases = sqlConx.GetSchema("Databases");
sqlConx.Close();

foreach (DataRow row in tblDatabases.Rows)
{
databases.Add(row["database_name"].ToString());
}
}
return databases.ToArray();
}

Here is a post of David Hayden detailing all the possibility of database reflection exposed by this method:


http://www.davidhayden.com/blog/dave/archive/2006/01/15/2734.aspx