Saturday, December 29, 2007

Server.MapPath Method

If you need to go to a file from your page, you may need to know the exact file path in order to access to it. In this case, you can use Server.MapPath method.Server.MapPath method takes a path as a parameter and returns the physical path corresponding to the path.For example, there is an xml file (database.xml) which stored a list of connection string is located in the C:\inetpub\wwwroot\webapplication1\database directory, and you need to get the connection string to connect to an appropriate database. The C:\inetpub\wwwroot...

Friday, December 28, 2007

List of Parameters Supported by Windows Media Player 7 and Later Version

By adding some PARAM elements in your Windows Media Player object, you can decide the outlook and the functionality of your Windows Media Player. It enables you to specify certain player properties when the page is browsed. Below is a list of common parameters supported by Windows Media Player and later version.autoStartDefault: trueDescription: Specifies or retrieves a value indicating whether the current media item begins playing automatically.balanceDefault: 0Description: Specify the current stereo balance.baseURLDefault:...

Thursday, December 20, 2007

Template Column VS Bound Column

This post will explain how to get information from your data grid for Template Column and Bound Column. There is so many times that when I am trying to retrieve the value of certain column from a data grid, I can get the value of the first column (Bound Column). However, I cannot get the value of the second column (Template Column). And both of the columns are not empty though.The explanation below is what I had found out finally.Basically, the difference between BoundColumn and TemplateColumn is that you have more control over...

Tuesday, December 18, 2007

Hiding and Showing Columns in the Data Grid

Some programmers have face the problem controlling the visibility of certain column in the Data Grid control. In this post, I will show you how to hide and show certain column in the data grid.Data grid control has a property called AutoGenerateColumns. By default, its values is set to True, which will contain all of the column names of the data set as you bind it with the data set. If you set the AutoGenerateColumns to True, then you would not be able to control the visibility of the columns. You can either use asp:BoundColumn...

Friday, December 14, 2007

Server.Transfer VS Server.Execute

Server.TransferServer.Transfer takes the control execution of the page to the new page and thereafter it doees not return to the original page. This execution happens at the server side and the client is unaware of the change, and hence it maintains the original URL. Server.ExecuteIn Server.Execute method, a URL is passed as a parameter, and the control moves to this specified page. Execution of code happens on this specified page. Once the execution is over, the control will return to the original page. This method is very...

Wednesday, December 12, 2007

Server.Transfer VS Response.Redirect

Example: A webform1.aspx wants to send the user to webform2.aspx.Response.RedirectResponse.Redirect method simply causes the client browser to move to another specified URL, as code below:Response.Redirect(“webform2.aspx”)When it is called, it will send a 302 (Object Moved) redirect header to the client browser, telling it that webform1.aspx has moved to webform2.aspx and then the browser will send a request to the server for webform2.aspx. When the browser receives responses from the server, it uses the header information to...

Tuesday, December 11, 2007

Adding an embedded Windows Media Player on HTML document

This article describes how to embed Windows Media Player to play music or video in HTML document, it also includes required code in HTML and JavaScript.To embed Windows Media Player, you need to add an OBJECT element for the Windows Media Player ActiveX control. Here is the code to add the OBJECT element on your web page.<HTML><HEAD><TITLE>Embedded Windows Media Player Web Page</TITLE></HEAD><BODY><OBJECT ID="Player" width="320" height="240" CLASSID="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"></OBJECT></BODY></HTML>As...

Sunday, December 9, 2007

Column Chart in Microsoft Excel

Charts or graphs are an important part of your spreadsheets to summarize your data, and allow you to see clearly the data trends and patterns in your spreadsheets. Here I will provide a step by step tutorial on creating a Column Chart in Excel.First step of all, you need to enter the data into the spreadsheet. From the figure below, you can see an example of data.Using your mouse to drag and highlight the cells that...

Friday, December 7, 2007

Import data from CSV file into data set

In this post, I am going to use the OLE DB Provider for Jet to connect to and query CSV file and then load the data into a dataset.First of all, I will import the following namespaces:Imports System.DataImports System.Data.OleDbAnd then there is a function which will load data from a CSV file and return a dataset.Private Function LoadCsvData(ByVal filename As String) As DataSet 'Create a new connection Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\;" & _...

Thursday, December 6, 2007

Simple script to play music on a HTML document

You can use this EMBED script to play a music in HTML document.Take a look at the example below. Hope this will help you work it out.<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta name="description" content="play music"><meta name="GENERATOR" content="Microsoft FrontPage 3.0"><title>Play music<SCRIPT language=JavaScript type=text/javascript><!-- function StartPlay (){document.track.Play()}function StopPlay(){document.track.Stop()}// --></script></head><body...

Wednesday, December 5, 2007

Create Folder in MS Access

Let say you want to create a new folder if it does not exist when you run your application, here is the sample code:Dim strFolder As StringstrFolder = "C:\New Folder"Dim fsoSet fso = CreateObject("Scripting.FileSystemObject")‘Check whether the folder existsIf Not fso.FolderExists(strFolder) Then FileSystem.MkDir (strFolder)End...

Tuesday, December 4, 2007

How to install a Font in Windows

1. Choose Start -> Settings -> Control Panel. Note: In Windows XP, choose Start -> Control Panel.2. Double-clicks the Fonts icon.3. Choose File -> Install New Font.4. Use the Folders Directory box to go to the location where the font was saved. (Use the "Drives" drop-down to select the appropriate drive, if not "C:")5. The font(s) in the selected folder will display in the "List of Fonts" box. Use Ctrl+click...

Monday, December 3, 2007

Create a New Recordset in VBA

Here is the sample code on how to create a new recordset.Sub Create_recordset()Dim rst As New ADODB.Recordset‘Add columnsrst.Fields.Append “Field1”, adVarchar, 50rst.Fields.Append “Field2”, adVarchar, 50…‘Create recordsetrst.Open()‘Add rows into recordsetrst.AddNew Array("field1", "field2"), Array("string1", “val1”)rst.AddNew Array("field1", "field2"), Array("string2", “val2”)End SubHappy programmi...

Saturday, December 1, 2007

VBA Worksheet

Delete worksheets For Each ws In oWB.Worksheets ws.DeleteNextAdd a worksheetSub Add_Sheet()Dim wSht As WorksheetDim shtName As StringshtName = Format(Now, "mmmm_yyyy")For Each wSht In Worksheets If wSht.Name = shtName Then MsgBox "Sheet already exists! " Exit Sub Else Sheets.Add.Name = shtName Sheets(shtName).Move After:=Sheets(Sheets.Count) Sheets("Sheet1").Range("A1:A5").Copy _ Sheets(shtName).Range("A1") End IfNextEnd SubCopy a worksheetSub Copy_Sheet()Dim wSht As WorksheetDim...

Friday, November 30, 2007

Get the Path to the MS Access Database (.mdb) File

For Access 2000/2002/2003'returns the database file nameCurrentProject.Name'returns the database pathCurrentProject.Path 'returns the database path and the file nameCurrentProject.FullName For Access 97'returns the database file nameDir(CurrentDb.Name) 'returns the database pathLeft(CurrentDb.Name,Len(CurrentDb.Name)-Len(Dir(CurrentDb.Name))) 'returns the database path and the file nameCurrentDb.Name'returns the directory that Access [msaccess.exe] is installed in(SysCmd(acSysCmdAccessDi...

Thursday, November 29, 2007

Replace apostrophe in PHP

When creating SQL statements, string values are delimited using apostrophes. So what happens when there is an apostrophe in the data you are trying to insert? A SQL error will occur if, for example, the value of a variable included an apostrophe. Because you do not know what the user will type in, you must assume they are entering all sorts of bad data. To insert an apostrophe into the database using SQL you need to put two apostrophes in the text where you want just one. For example, to insert the phrase "what's it?" into a...

Tuesday, November 20, 2007

Pass Parameter Value from Form to Query

Recently working with extracting data from Access Database and export it to an excel file. To achieve all these, I created a query that pulls up some data from a table which contains a condition that must be filled in by the user. In other words, I need to pass parameters from Form to Query.Hence when I ran the query, there is an “Enter Parameter Value” dialog box prompted out that must be filled. This is because the query itself actually has a WHERE statement, for example SELECT * FROM table_name WHERE field_name = VAR1;I tried...

Monday, November 12, 2007

Timeout Expired in ASP .NET

This error occurs when a database query or stored procedure’s execution time beyond a pre-set timeout period. When you are trying to retrieve a huge amount of data, more execution time may be required.There are 2 main Timeout properties in .NET:1. Connection Timeout – It could be solved by setting ConnetionTimeout property in your connection string. For example:<add key="DBConnection" value="server=localhost;uid=sa;pwd=;database=dbName;Connect...

Wednesday, November 7, 2007

HIDE/UNHIDE ROW/COLUMNS IN EXCEL

Sometimes when you open an Excel file, you will notice that some columns are missing. This is one of the features to unhide and hide rows and columns in the worksheet without affecting calculations in any way. Hiding rows and columns can be displayed in two ways:1. Select rows and columns that you wish to hide, and then go to Format -> Row or Column -> Hide. 2. Select rows and columns that you wish to hide, and...

Tuesday, November 6, 2007

ORACLE ERROR: ORA-28000: The account is locked

One of my colleagues is getting the following error when tried to logging into a business object which using oracle database, and got this error. Finally a quick web search gave the solution. Cause: The user has entered wrong password consequently for maximum number if times specified by the user’s profile parameter FAILED_LOGIN_ATTEMPTS or the DBA has locked the accountAction: Wait for PASSWORD_LOCK_TIME or contact DBADBA must unlock these accounts to make them available to users. Look at the script below to unlock a user:ALTER...

Monday, November 5, 2007

Run a Query to Show All Table

Mysql:This allows you to see all existing tables inside the database selected. mysql> SHOW TABLES;Oracle:Oracle doesn't support the above command, though an equivalent would be to use this sql statement: sql > SELECT * FROM tab WHERE TABLE_TYPE = 'TABLE'; orsql > SELECT * FROM cat WHERE TABLE_TYPE = 'TABLE'; orsql > select * from user_objects where object_type = 'TABLE';SQL Server:Run the script below in your query analyzer.SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TAB...

Saturday, November 3, 2007

如何拯救遗失文件

前几天在报章上看到了“拯救遗失文件有妙方”的报导,想和大家分享一下。电脑系统崩溃,重新装置软件系统,把原本存档的文件都给删除了,这是多么令人头痛的事。许多人不知道原来各种数码资料,包括储存在电脑硬盘,相机,手机,录像机,还有还有CD,DVD光碟,MP3曲目,删除了都能被拯救还原的。一般人认为按了Delete按钮后,资料就找不回了,其实并不然。当你删除某些资料时,电脑操作系统(Operating System)只是把资料所占据的硬盘空间贴上(free space)标志,之后再重用这一块空间来记录其它资料。但是如果时间过得太久了,同一块空间被重复用了很多次之后,以前的数据就未必能找的回了。如何拯救文件当我们不小心删除了重要文件时或电脑系统倒垮时,首先要确保不要再继续储存新的文件,以免资料被改写。如果使用Windows电脑视窗,可先到“回收站”(Recycle Bin)文件夹检查该文件是否还在。如果还在,按“全部恢复”即可。如果文件已经不在“回收站”了,只要不再加入新资料改写了原本损失资料的位置。请依照以下指示:1. 从www.adrc.net下载“ADRC Recovery Tools”的免费软件。它能帮助“复删除”(un-delete)文件。2....

Something useful with virtual Keyboard

An alternative keyboard in Windows -In case your keyboard or some keys stop working, Microsoft provides you with an alternative way to type in using the mouse.To work this tool, goes to 'Start menu'Then Select 'Run'Type in 'OSK'Press OKA keyboard will appear that you can use as normal keybo...

Friday, November 2, 2007

Splitting a Microsoft Access Database

In this article, I will mention about the pros and cons of splitting the database, and implementing how to split a database step by step.Generally, you will split your MS Access database into front-end database and back-end database, which back-end application will contains only the database table and front-end application will contain all of the queries, forms, reports, macros and modules. In a multi-user environment, the front-end database will be distributed to each client machine, and the back-end database will be installed...

Thursday, November 1, 2007

Option Explicit and Option Strict in VB .NET

Generally it is a MUST to put ‘Option Explicit’ and ‘Option Strict’ at the top of all my .net classes. Option Explicit StatementBy default, the Visual Basic .NET or Visual Basic 2005 compiler enforces explicit variable declaration, which requires that you declare every variable before you use it.Option Strict Statement‘Option Strict’ keeps VB developers coding bad casts. By default, the Visual Basic .NET or Visual Basic 2005 compiler does not enforce strict data typing.In Visual Basic .NET, you can convert any data type to any...

Wednesday, October 31, 2007

Export Data From MS Access to Excel File

I passed data from MS Access to Excel recently, so I would like to share the techniques and code that I used. Firstly, a reference is needed to be made to Microsoft Excel. To add a reference, go to Tools -> References while working in any code module. As shown from the list, I am using Excel 11 (Office 2003). Look for the Microsoft Excel Object Library that is available on your computer and click the check box.Here...

Tuesday, October 30, 2007

Import Data from Excel File (.cont)

As I has stated in my previous post regarding to Export Data Form an Excel file, there is one drawback lying behind them. The Sheet1 from the query actually is the name of the spreadsheet in your excel file. What if there is no Sheet1 inside the excel file? What if you don’t even know the sheet name? Yes. I found this error when I tried to upload an excel file with different sheet name. And here is the solution for that.To get the sheet name in your excel file, firstly, Microsoft DAO 3.5 Library is needed. Go to Project ->...

Friday, October 26, 2007

CAPITAL LETTERS ONLY in Combo Box

For some reasons, you may need to let users key in ONLY CAPITAL LETTER in your text box or combo box. In the Key Down event, you can capture the key that user has entered and from there, convert the letter to capital letter and return to the text box. Instead of Key Down, you can also use Key Press event. The following codes will make it. Try it out yourself.Private Sub TextBox1_KeyPress (KeyAscii As Integer) Char = Chr(KeyAscii) KeyAscii = Asc(UCase(Char)) End ...

MAINTAINING SCROLL POSITION IN A WEB USER INTERFACE IN ASP .NET

Some people have problems in maintaining scroll position for a web page after a post back is performed. I had posted an article in PHP example, Maintaining Scroll Position in a Web User Interface in PHP last time.There is a very simple solution to apply this in ASP .NET. You can just turn on the “Smart Navigation” in the Properties of ASP .NET. But sometimes it can mess up with other JavaScript. Alternatively, you can just add a Java Script to keep the scroll position. Similar with PHP example, firstly, you need two hidden fields...

Thursday, October 25, 2007

MAINTAINING SCROLL POSITION IN A WEB USER INTERFACE IN PHP

Anyone who is creating a very long Web Form that entails a lot of post backs may encounter to the user interface problem that occurs in such scenario that loss of scroll position on each post back (namely, if you scroll down to the middle of a long page, and after the browser refreshed, the scroll position is lost).For this case, using Java Script for keeping the scroll position is the best way to go. Java Script can help us to know the current position of the browser.Firstly, you need two hidden fields in your form to store...

Wednesday, October 24, 2007

Dealing with apostrophes in SQL strings

In many applications, the developer has side-stepped the potential use of the apostrophe in some of the text fields. So when adding values to a table, be aware that problems may be caused by embedded apostrophes in a string. Consider the SQL Insert statement below.INSERT INTO table_name (table_field_name) VALUES (‘O’reill’, ‘92314567’) Notice that there is an apostrophe in the text “O’reill”. In SQL, the apostrophe is an illegal character. It is interpreted as a string delimiter or the end of the string. So when it encounters...

Tuesday, October 23, 2007

Embedded Java Script in ASP .NET

Many developers like to use the flexibility of writing Java Script in ASP .NET to achieve the functionality they need or notify users of some server-side behavior. For example, if there was some server-side error and the data entered weren’t correctly saved, or the data entered by users are not in the correct format. In this case, we might want to pop up alert message box to inform the users. Basically there are two ways to write a java script code in ASP .NET. Either call the java script in the html of the page by creating...

Monday, October 22, 2007

DELETE FROM and TRUNCATE table functionality

There are two main commands used for deleting all the data from a table: TRUNCATE and DELETE FROM. Two of these achieve the same result; however there are significant differences between the two. There are advantages, limitations and consequences that you should consider to decide which one to use.About TRUNCATE TRUNCATE command is faster because it removes all records in a table by deallocating the data pages used by the table, thus reduces the resource overhead of logging in the log and the number of acquired locks as well....

Sunday, October 21, 2007

Access Error: XXX DB can't append all the records in the append query

Currently I am working on a small project using MS Access Database. Since I am not so expert with the MS Access, it really brings me a lot of problems and spent me a lot of time too.I tried to insert a new record into my database, but it kept came up with the message belowXX DB can't append all the records in the append query.XX DB set 0 field(s) to Null due to a type conversion failure, and it didn't add 0 record(s) to the table due to key violations, 0 record(s) due to lock violations, and 1 record(s) due to validation rule...

Saturday, October 20, 2007

Request.ServerVariables (“LOGON_USER”) Error

Active Server Pages exposes an object called ServerVariables, which is part of the Request object. This ServerVariables object allows the programmer to see many environment variables. You can use the ServerVariables along with Internet Information Services (IIS)’s directory security options to determine who is currently accessing your site. You can also grab the visitor's IP address using the ServerVariables object.In some .NET projects, when you try to access the Request.ServerVariables (“LOGON_USER”) variable in ASP .NET,...

Friday, October 19, 2007

A Simple Solution for Export ASP .NET Data Grid to Excel

This sample demonstrates an easy way to export DataGrid into an Excel file. Most of the web controls have a RenderControl method which will write an html text stream. All have to do is declare the response object, call RenderControl method and output the “rendering”. Quite simple!Here is the code for the Export method:Public Shared Sub ExportToExcel(ByVal dg As DataGrid, ByVal lblTitle As Label)TryIf dg.Items.Count > 0 ThenHttpContext.Current.Response.Clear()HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"HttpContext.Current.Response.AddHeader("content-disposition",...

Thursday, October 18, 2007

Task Manager Had Been Disabled By Your Administrator

Yesterday, my friend called me for help because her computer has been infected by some kinds of spyware and caused an error – Task Manager being disabled. If this happens normally you will need to edit the Windows Registry to fix it. Listed below you will find some ways to re-enable Task Manager.Method 1 – Using Group Policy Editor in Windows XP Professional1. Start > Run > gpedit.msc > OK.2. Under User Configuration, expands the Administrative Templates.3. Under Administrative Templates, expands System, then click...

Wednesday, October 17, 2007

How to Import Data from Excel File

This article provides a very simple example of how to query an Excel spreadsheet from an ASP.NET page using VB .NET. Check it out!Sub Page_Load(sender As Object, e As EventArgs)Dim ds As New DataSet()Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _"Data Source=C:\test.xls;" & _"Extended Properties=""Excel 8.0;"""Dim da As New OledbDataAdapter("SELECT * FROM [Sheet1$]", strConn)da.TableMappings.Add("Table", "Excel")da.Fill(ds)DataGrid1.DataSource = ds.Tables(0).DefaultViewDataGrid1.DataBind()End SubGood...
 

Get paid for your opinions! Click on the banner above to join Planet Pulse. Its totally free to sign up, and you can earn UNLIMITED. Find out more by visiting PLANET PULSE.
Sign up for PayPal and start accepting credit card payments instantly. http://www.emailcashpro.com
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template