Thursday, December 28, 2006

char, varchar, nchar, nvarchar

nchar and nvarchar are used for unicode data, which require twice as much space (bytes) to store the same non-unicode characters. It is a significant disadvantage to use nchar and nvarchar if we do not need unicode charactors. Only use nchar & nvarchar when you need unicode charactors
use char & nchar when the length of the data is fixed, e.g. all customerID must be CUST_XXXX. use varchar and nvarchar when the length of the data is uncertain, e.g. customerID starts from 1 to 100000.

Monday, December 18, 2006

asp.net2.0 upload file

use FileUpload control. this example checks for file type, empty file

protected void btnSaveFile_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = @"C:\temp\";
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < fileextension ="="" fileok =" true;" text = "File uploaded!" text = "File could not be uploaded." text = "Cannot accept files of this type.">

reference: http://msdn2.microsoft.com/en-us/library/ms227669.aspx

Thursday, December 14, 2006

ASP.NET 2.0 “Ambiguous match found” error

when trying to load an ASPX page. The error was a “Parser Error” with “Ambiguous match found”.
The problem could be caused by having a member variable and a control variable with the same name (but different casing)
e.g.
private double aVariable = 0;
AnVariable.Text = aVariable .ToString("c");

The code will compile, and will run locally, but fails when deployed.

The solution is to rename the private member variables

*Thanks to Simon for the finding
*the reference: http://weblogs.asp.net/pjohnson/archive/2006/08/11/Ambiguous-match-found.aspx

Wednesday, December 06, 2006

unit testing issue (access denied - aborted) - VS Team - Developers

Symptom:
when i try to test a method, the result says "Aborted", and the error message was:
"Failed to Queue Test Run "@MACHINE1" 2006-12-04 17:13:30' with id {********-****-****-****-************}: Microsoft.VisualStudio.TestTools.TestManagement.ExecutionException: Test Run deployment issue: The location of the file or directory '\\server1\users\ab\my documents\visual studio 2005\projects\webservicepractice1\testproject1\bin\debug\testproject1.dll' is not trusted."

Solution
1. Control Panel --> .NET Framework 2.0 Configuration --> Runtime Security Policy --> Machine --> All_Code
2. Right click All_Code, select "New...", and give a name for your new group. Click Next and Next again
3. Type in "\\machine_name\shared_folder\assembly.dll" or "\\machine_name\shared_folder\*" and click Next
5. Make sure permission is set to FullTrust. Click Next, and Finish

.NET should be closed all the time while doing these settings

Thursday, November 30, 2006

create & call stored procedure in ASP.NET 2.0 & MSSQL DB

<--CREATE-->
ALTER PROCEDURE dbo.NumOfRecords
AS
SELECT COUNT(*) FROM Branding
RETURN

<--CALL-->
protected void Button8_Click(object sender, EventArgs e)
{
SqlConnection newConn = new SqlConnection("Data Source=localhost;Initial Catalog=TCdatabase;Integrated Security=True;Pooling=False");
SqlCommand newComm = new SqlCommand("NumOfRecords", newConn);

newConn.Open();
int theTotal = (Int32)newComm.ExecuteScalar();
Response.Write(theTotal.ToString());
newConn.Close();
}

messagebox in ASP.NET 2.0

The basic concept is to use JavaScript. Below only shows one way of implementing javascript for messagebox:

switch (txtName.Value)
{
case ("aaa"):
Page.ClientScript.RegisterStartupScript(this.GetType(),"Alert","< script language="javascript" >alert('AAA');< /script >
");
break;

case ("bbb"):
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "< script language="javascript" >alert('BBB');< /script >
");
break;


}

Wednesday, November 22, 2006

deploy applications that use Microsoft SQL Server 2005 Express Edition (SQL Server Express),

http://msdn2.microsoft.com/en-us/library/ms165639.aspx

Monday, November 13, 2006

realize inputBox in C#.net by referencing VB.net component

this will add VB.NET runtime dependency in C# application, you can even add a reference to Microsoft.VisualBasic assembly and call InputBox function implemented there:

string aaa = Microsoft.VisualBasic.Interaction.InputBox("enter a name", "Inputbox Demo", "ROCKY", 100, 100);
MessageBox.Show(aaa);

Another way of doing it without referencing VB.net is to create a form that looks like an inputBox:


using System;

namespace MyNamespace
{
public class InputDialog : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button cmdOK;
private System.Windows.Forms.Button cmdCancel;

public string Value
{
get
{
return txtInput.Text;
}
set
{
txtInput.Text = value;
}
}

public InputDialog()
{
// Required for Windows Form Designer support
InitializeComponent();
}

private void InitializeComponent()
{
this.txtInput = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.cmdOK = new System.Windows.Forms.Button();
this.cmdCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(48, 16);
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size(232, 20);
this.txtInput.TabIndex = 0;
this.txtInput.Text = "";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(33, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Input:";
//
// cmdOK
//
this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.cmdOK.Location = new System.Drawing.Point(69, 48);
this.cmdOK.Name = "cmdOK";
this.cmdOK.TabIndex = 2;
this.cmdOK.Text = "OK";
//
// cmdCancel
//
this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cmdCancel.Location = new System.Drawing.Point(149, 48);
this.cmdCancel.Name = "cmdCancel";
this.cmdCancel.TabIndex = 2;
this.cmdCancel.Text = "Cancel";
//
// Form1
//
this.AcceptButton = this.cmdOK;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cmdCancel;
this.ClientSize = new System.Drawing.Size(292, 86);
this.Controls.Add(this.cmdOK);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtInput);
this.Controls.Add(this.cmdCancel);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}

Sunday, November 05, 2006

convert sting value to the value of datetimepicker

generally the format should be everything except the AM part.

DateTime result = DateTime.Now;

if (DateTime.TryParse(this.label1.Text, out result))

{

this.dateTimePicker.Value = result;

}

We can also use DateTime.TryParseExact:
http://msdn2.microsoft.com/en-us/library/h9b85w22(VS.80).aspx

Saturday, November 04, 2006

WinXP folder/file sharing ------ create a hiden share

A> create a hiden share
1. right click disk or folder you want to share and click on Sharing and Security
2. specify a share name with 1 - 11 characters, end with a "$"
3. if want to give edit rights, click on "allow net work users to change my files


B> access the hiden share
1. My Computer --> Tools --> Map Netwok Drive
2. give an unused drive letter and network parth of the hiden share, make sure to include the "$"
3. if select "Reconnect at logon", connection will be connected everytime start the pc, otherwise have to manually map everytime

Thursday, November 02, 2006

inputbox in C#.net 2005 winform app

C# does not support inputbox, but C#.net2005 can have added reference to Microsoft.VisualBasic.dll

then in C#.net2005, you will be able to something like:

private void button3_Click(object sender, EventArgs e)
{
string userInput = Microsoft.VisualBasic.Interaction.InputBox("Give me something, I will tell you what you got?", "Question Popup", "Default Text",400,400).ToString();
MessageBox.Show(userInput);
}

use of YesNoCancel in messagebox.show() method in C#.net 2005 winform application

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = false;
DialogResult result = MessageBox.Show("Do you want to save any changes before closing this window? \n\n Click on 'Yes' to save; or \n Click on 'No' to close without saving; or \n Click on 'Cancel' to do nothing.", "Closing Window", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);

if (result == DialogResult.Yes)
{
MessageBox.Show("you clicked on YES, c u!");
}
else if (result == DialogResult.No)
{
MessageBox.Show("you clicked on NO, c u!");
}
else
{
e.Cancel = true;
}
}

Tuesday, October 31, 2006

detailed explanation of application.settings in C#.net 2005

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/SettingsCS_RL.asp

Monday, October 30, 2006

make databound checkbox checked in C#.net2005 winform application

normal checkbox can use checkbox1.checked = true;

databound checkbox needs to change the checkstate: checkbox1.checkstate = checkstate.checked;

make databound checkbox checked in C#.net2005 winform application

normal checkbox can use checkbox1.checked = true;

databound checkbox needs to change the checkstate: checkbox1.checkstate = checkstate.checked;

check whether form is already opened in C#.net 2k5 winform application

created the form object in application settings

Code to open the form:
private void button1_Click(object sender, EventArgs e) {

if ( Properties.Settings.Default.frmReg == null )
{
Properties.Settings.Default.frmReg = new frmRegistration();
Properties.Settings.Default.frmReg.Show( this );
}
else if ( Properties.Settings.Default.frmReg != null && Properties.Settings.Default.frmReg.WindowState ==

FormWindowState.Minimized)
{
Properties.Settings.Default.frmReg.WindowState = FormWindowState.Normal ;
}
else
{
Properties.Settings.Default.frmReg.Focus();
}
}

Code to close the opened form:
Properties.Settings.Default.frmReg = null;

something wrong with goggle?

what's happening with blogger.com? the whole weekend and this monday morning, sometimes can't create a new post, sometimes changes to the template are not reflected, come on!!!!!

Sunday, October 29, 2006

check whether form is already opened in C#.net 2k5 winform application

created the form object in application settings

Code to open the form:
private void button1_Click(object sender, EventArgs e) {

if ( Properties.Settings.Default.frmReg == null )
{
Properties.Settings.Default.frmReg = new frmRegistration();
Properties.Settings.Default.frmReg.Show( this );
}
else if ( Properties.Settings.Default.frmReg != null && Properties.Settings.Default.frmReg.WindowState == FormWindowState.Minimized)
{
Properties.Settings.Default.frmReg.WindowState = FormWindowState.Normal ;
}
else
{
Properties.Settings.Default.frmReg.Focus();
}
}

Code to close the opened form:
Properties.Settings.Default.frmReg = null;

testing post

testing post

Thursday, October 26, 2006

using OleDbCommand class to update a database table based on one or more variable values C#.net 2005 winform app

using ( OleDbConnection connection = new OleDbConnection( Properties.Settings.Default.HPMConnectionString ) )
{
connection.Open();
OleDbCommand changeActiveToNoCommand = new OleDbCommand( "UPDATE staff SET active = no WHERE staff_id = @staff_id" , connection );
changeActiveToNoCommand.Parameters.AddWithValue( "@staff_id" , Convert.ToInt64( staff_id ) );
changeActiveToNoCommand.ExecuteNonQuery();
}

using OleDbDataReader class to retrieve a value based on one or more variable values C#.net 2005 winform app

string staff_no = staffDataGridView.CurrentRow.Cells[0].Value.ToString();

string staff_id="";

using (OleDbConnection connection = new OleDbConnection(Properties.Settings.Default.HPMConnectionString))
{
//OleDbCommand findStaffIDCommand = new OleDbCommand("SELECT staff_id FROM staff WHERE staff_no = '" + staff_no + "'", connection);
OleDbCommand findStaffIDCommand = new OleDbCommand( "SELECT staff_id FROM staff WHERE staff_no = @staff_no",connection );
findStaffIDCommand.Parameters.AddWithValue( "@staff_no" , staff_no );

connection.Open();
OleDbDataReader reader = findStaffIDCommand.ExecuteReader();

while (reader.Read())
{
staff_id = (reader[0].ToString());
}
reader.Close();
}
MessageBox.Show( staff_id.ToString() );

Wednesday, October 25, 2006

dataGridView show value of any cell on selected row (multiRow select = false) C#.net 2005

MessageBox.Show(clientsDataGridView.CurrentRow.Cells[0].Value + "");

Tuesday, October 24, 2006

tooltip in VS2005 winform and asp applications

in winform applications, there is a component called "tooltip", which can be referenced by other visual components

in asp.net applications, there is a property called "tooltip" for most of the visual components, which can be used to enter single line tooltipss.
There is a third party tooltip utility called "cooltip", which is much more powerful:
http://www.acooltip.com/index.html#

Sunday, October 22, 2006

make combobox readonly in C#.net 2005 winform application

change the value of property "DropDownStyle" to "DropDownList)

referencing other classes C#.NET 2005

if you create a class within a subfolder of a winform project, you can't reference it within he code of a class in the root folder of project.
Solution:
to create the class in the same folder/rootlevel as the class that needs to have referencing code, and then move the class into anyother folder

access application settings in code C#.NET 2005

to access the values predefined in application settings, do this:
label1.Text = Properties.Settings.Default.aaa;
aaa is the name of the variable;

to persist the change, do this:
Properties.Settings.Default.aaa = "bbb";
Properties.Settings.Default.Save();

Wednesday, September 27, 2006

i am back

it's been a while.....
busy doing my masters and working at the same time. have to submit a report next monday, another one is coming soon.

feel lost.....

Saturday, May 13, 2006

force number input in .NET



This built-in function can be used to force user to input numbers:

if (!char.IsNumber(e.KeyPress))
messagebox.show("plz enter numbers only")

also, "decimal.tryparse" can be used to check if the input is a number after input

Friday, May 12, 2006

my babies


some of them are alomost 2 months old, majority are 3 wks or 1 wks old, happy begging for food all the time, never enough~

They energize my study and work as well as relax me when I am tired:)

Fibonacci Sequence number calculation (int16)

this chunk of code calculates Fibonacci Sequence number base on user input using C#.NET:

private void btnGetNumber_Click(object sender, EventArgs e)
{
try
{
if (txtInput.Text == "" txtInput.Text == null) //to avoid empty input
{
MessageBox.Show("Please input a positive Integer between 0 and 62", "Error: Empty Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtInput.Clear();
txtInput.Focus();
}
else
{
int theNum = Convert.ToInt16(txtInput.Text);
if (theNum == 0) //to avoid zero input
{ MessageBox.Show("Please input a positive Integer between 0 and 62", "Error: Zero Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtInput.Clear();
txtInput.Focus();
}
else if (theNum <> 46) //to avoid overflow result, if the variables are defined for bigger values, this condition should be commented out and use OverflowException
{
MessageBox.Show("Please input a positive Integer between 0 and 62", "Error: Result Overflew", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtInput.Clear();
txtInput.Focus();
}
else //all conditions met, calculate the result
{
int numA = 0; int numB = 1; int numC;
for (int i = 1; i <= theNum; i++)

{
numC = numA;
numA = numB;
numB = numC + numB;
}
//print result to screen
lblAnswer.Text = numA.ToString();
} } }
//uncomment the code below for catching overflow exception when the variables are
//defined as uint64 or ulong, that is, too big to guess the limit
//catch (OverflowException)
//{
// MessageBox.Show("Please try again with another smaller positive Integer", "Error: Result OverFlow", MessageBoxButtons.OK, MessageBoxIcon.Error);
// txtInput.Clear();
// txtInput.Focus();
//}
//throw error for string or decimal inputs
catch (FormatException)
{
MessageBox.Show("Please input a positive Integer between 0 and 62", "Error: String or decimal Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtInput.Clear();
txtInput.Focus();
}
//throw error for unknown errors
catch (Exception ee) { MessageBox.Show("Error: Unknown", ee.Message); Application.Exit(); } }

validate positive integer from user input

uint holds only positive numbers, this event checks if the input is a validate positive integer, otherwise throw error using C#.NET

private void button1_Click(object sender, EventArgs e)

{

uint value = 0;

if (!uint.TryParse(textBox1.Text, out value) value == 0)

{MessageBox.Show("Wrong format");

return;}

textBox2.Text = value.ToString();

}

Tuesday, May 02, 2006

PHP sample login code


just done a sample, hope its helpful for newbies like me
Click here to download phploginsample.rar. Don't forget to create a db called news_users, with 3 columns "username" (varchar/char, PK), "passwd" (varchar/char), and "access_level"(smallint, 0 or 1).

lesson learnt from PHP Parse error


silly word wrap, some environment doesnt support automatically word wrap when copy and paste code. so the solution is:

put "//" in front of every line of comment to prevent the error caused by a multiline comment led by only have "//" in front of first line.

copy-pasters be aware!

Thursday, April 20, 2006

Check whether a session is started in PHP


this line will check if a session has started, if not, start it:

session_id() or session_start();

another alternative:

if(!session_id())
{
session_start();
}

Tuesday, April 11, 2006

Long time no see~

havn't been here for a while, master study is really stressful.
anyway, got some good news too, 3 of the baby guppies grew up already and ready to meet their new owner, I am going to deliver them tomorrow morning, hope they will enjoy their new home! One thing I am sure is that they will get much more sunshine overthere.
Time for bed, night all~

Friday, March 24, 2006

how come all the ads disappeared?

Too busy to check it out, bye ads!

Thursday, February 23, 2006

another week

it's been over a week since the V day. How is everything? I am still having headache doing my ASP.NET2.0 website, it's soo different compare to win-forms apps while communicating to the db using ADO.NET. Maybe it's just me having problem understanding the concept of web applications. Hope I can still get something done before new semester starts, I dont think so anyway.
It's 3:57 am, late again? I need to get back to day shift, lol. My classes are all in the afternoon, it should be ok anyway. I really want to get another couple of HDs for this master degree!!!!!!!!!! I am desperate~~~~~~

Tuesday, February 14, 2006

Good day and Bad day

I had 2 good news today, they are very very important to me. I also have 1 bad news, which will screw my V day, anyway, let me take my time get it fixed. At least I got something to do on this lonely V day.

Happy V day to all!

Saturday, February 11, 2006

ok, got you all!


when i got up today, there were 14 babies, haha, that's a big number!
I put the 4 borned a week ago together with these 14 babies, hey, they grew sooo quick within a week! The wierd shape ones all look normal now, good good!
Chris asked me for snorkeling tomorrow or the day after, he is crazy, I just heard there are dozen sharks wandering around the nearby beaches. I havn't lived long enough, haha, I will tell him dont go too, and go play basketball with me. good idea?

Friday, February 10, 2006

Happy birthday new guppy babies!!!!!


I think I need to learn more about ASP.net 2.0 before I start planning my website, because my limited development knowledge (in terms of technology/language) will seriously limit my imagination, agree?

Hey, you should all be excited as me, last night I saw one of the ladies in my tank was having delivery symptom, so I moved her into delivery area. when I just about to go to bed 15 minutes ago, i glanced at the tank, you know what, I saw 2 babies swiming! in just a second, the number became 3, I kept watching for 5 minutes, let me count..... there are..... one more!!! haha, 7 now!!!! it's sooooo emotional watching the little ones evacuating out of their mum's body. If I count now there might be more, but I will let her do her job~

I figured out 2 or 3 of the new borned babies are not very healthy looking, got huge bellys, dont know why, hope they will look normal soon, otherwise..... I dont know what's gonna happen. the mum seems struggling, jumping up and down, you know what, she is giving birth with a very long pull hanging out of her ass, how can she give birth and go to toilet at same time? that's amazing! oh yeah, as I heard, female is generally good at multi-tasking, here we go!

Let me know if you want to share your love with some of the babies, they will soon turn into gorgeous colors, maybe in just 2 weeks time.

ok, time to say good morning (my sleeping time), bye for now~

Wednesday, February 08, 2006

empty night, not much done~

oh well, another night, dived into MySQL, made the connection work, created a db with couple of tables, all easy stuff, but cant figure out why it asks me for the bloody pw when I try to edit table data. Then jumped into ASP.NET, found out a good site with complete tutorial targeting to those who have developed webpages (I have never, but I think I will be able to handle it with the knowledge gained during these days readings). fingure cross. I will try to complete this tutorial asap with quality, as well as planning for my first asp site. So when the time comes to start building, I will at least have some clue (no I am totally blind on the development concept of web application). Oh yeah, almost forgot to mention, I found a free asp.net app hosting offer, awesome! check it out:
http://www.brinkster.com/

Tuesday, February 07, 2006

boring night


Read through heaps of stuff last night: PHP, MySQL, XSLT&XML. Edited some php pages in Dreamweaver, all the same result during preview: page not found!!!!!, wondering why, maybe I need to install MySQL. Then It threw error when I was trying to connect to localhost under MySQL Administrator after MySQL and administrator tool were installed. I think there must be some kind of problem with coexistance of MSSQL and MySQL. But anyway, I am going to blueprint my first ASP.NET2005 website, it's much more intelligent to work with .NET2005. Very humid and hot, how I am gonna sleep? Good Morning All~

My guppy babies are growing well


one of my female guppies delivered 4 little ones on 02/02/06, now they are 5 days old, active and spoiled, lol! I tried to figure out their sex, I think 2 of them are definitely gals, one boy, and the 4th one not very sure. They love egg's yolk. Hope the big ones don't jump into the cradle and eat them all~

Monday, February 06, 2006

Today is an exciting date!


well, time for sleep now, hopefully I can get up and be at vice-chancellor's presentation in time. Good Morning everyone! zzZZZZZzzzzzzzzzzZZz~~~~~

Sunday, February 05, 2006

is it friday or saturday now?


Whole night, had quick study on JavaScript, gave a shot on DHTML and overviewed DOM, can I say that I am more confident of starting my first hard-coded website? maybe I shouldn't rush really~. I think I better get back to the original starting point -- ASP.net 2005. Yeas,I need a plan first, it will be a lot easier for me to learn from building an actual website, firstly, static, presentation layer (see if i can code it) and then the backend will be with asp.net, anyway, I need some time to think of the plan, haha, PLANNING, important!

Saturday, February 04, 2006

another long night~


CSS was covered last night, so far I roughly learnt HTML,XHTML and CSS, got basic idea of better presentation layer building method. check out my study result at "My Site" on the right hand side list of this page, all the pages on this site are my own work~

Wednesday, February 01, 2006

Who wants to come with me?



I am in Vice-Chancellor's list for good performance in sem2 2005, got invited for the presentation on 6th Feb, which is next monday late afternoon. You are all welcome to be my guests, plz contact me for details

Saturday, January 28, 2006

Happy Chinese New Year!!!!!


My fourth Chinese New Year in Perth, Hope all my family and friends are very well, and enjoy new year celebration! Wish you all the best in the new Chinese Year!
祝大家:
买房挖到财宝
股票统统解套
彩票头奖中到
老婆怀上宝宝
阿弥陀佛笑倒
新年佛脚抱牢
龙马精神,更上一层楼!

Thursday, January 26, 2006

My first post on this blog


Hello world, Happy Australian Day to All~~~
Hope you all enjoying the beautiful weather while I am sleeping :)