Search this insane blog:

Wednesday, July 30, 2008

Create a function to convert decimal to fraction

http://blogs.techrepublic.com.com/datacenter/?p=348

execute javascript on page

private void SetFocus(Control ctrl)
{
// Define the JavaScript function for the specified control.
string focusScript = "";
// Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript);

asp.net 2.0 with c#: Accessing connection string using code behind

-- straight away connection
private void Page_Load(object sender, EventArgs e)
{
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();

// perform work with connection

}
}
--- to encapsulate a connection stored in your web.config
private void Page_Load(object sender, EventArgs e)
{
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();

// perform work with connection

}
}

----------------------------
private void Page_Load(object sender, EventArgs e)
{
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();

// perform work with connection

}
}



you can read the details at odetocode...
source: http://www.odetocode.com/Articles/345.aspx

Tuesday, June 24, 2008

Find Indexes on columns

SELECT OBJECT_NAME(sys.sysindexes.id) AS [object name], INDEX_COL(OBJECT_NAME(sys.sysindexes.id), sys.sysindexes.indid, 1) AS [column]



FROM sys.sysindexes
INNER JOIN



sys.sysobjects
ON sys.sysobjects.id = sys.sysindexes.id



WHERE (sys.sysobjects.xtype
IN ('u', 'v')) AND (sys.sysindexes.status
= 0) AND (INDEX_COL(OBJECT_NAME(sys.sysindexes.id), sys.sysindexes.indid, 1) IS NOT NULL)



ORDER BY [object name]

Sunday, June 15, 2008

Membership database permissions.

sp_help 'aspnet_CheckSchemaVersion'
-- if the website has an error lke
-- EXECUTE permission denied on object 'aspnet_CheckSchemaVersion'...
-- look inside your database to decide who gets permissions.

sp_addrolemember 'aspnet_Membership_FullAccess', 'username'


note: if you don't know anything about asp.net memberships and have the SQL server management studio, search for the application on your computer called aspnet_regsql.exe.

That will pop up a wizard and will install the membership database you will neeed for membership on your asp.net website.

background: I stumbled upon this when I installed asp.net's default personal webpage template.

Thursday, April 3, 2008

grabbing a csv from a csv file

I created this code, but haven't tested the values with a schema.ini file yet. My old programming co-worker had this working quite well.

----

I typically use a ssis package with a credential (previous blog) to do this, but my friend does it this way .. well, he is testing it.
He is having trouble initiating with a schema.ini file..




EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE with
override
GO
IF OBJECT_ID('#MyTable') IS NOT NULL
BEGIN
DROP TABLE
#MyTable
END
SELECT *
INTO #MyTable
FROM
OPENDATASOURCE(
'Microsoft.Jet.OLEDB.4.0'
,'Data
Source="C:\Event_Leads\G2WAttendee_02125312";Extended
Properties="text;HDR=No;FMT=Delimited";'
)...[G2WAttendee#csv]
Select *
from #MyTable
DROP TABLE #MyTable
EXEC sp_configure 'Ad Hoc Distributed
Queries', 0
GO
RECONFIGURE with override
GO
EXEC sp_configure 'show
advanced options', 0
GO
RECONFIGURE
GO

Presenting a "Pretty" date

I typically date my items as

01/15/2008 for January 15, 2008.

Here is a pretty way of transforming this:


SELECT , CONVERT(VARCHAR(12), ExpDate, 1) AS Expires


-- create a #session table so it will be cleaned up when
you close out of the window

INTO [#Oneyear]
FROM Mytbl