Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello Everyone

i have attended the lot of interview and cleared the telephonic round in all the companies but when i am attending the machine test rounds maximum companies are told that you code is very basic level and your code is not like 2+ exp ,but i have complete the task always what they given, in my organization i am only the developer, i dont have existing project in my concern . actually i dont know how to write the code in procedural way for asp.net with C#, is there any format for upgrade my coding ,or is there any links to refer

this may be help not only for me,this may help many peoples so is there any way to write code typically please let me know

here is my coding

C#
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Session.Clear(); 
Session.Abandon();
}
}
protected void submit_Click(object sender, EventArgs e)
{
username = Request.Form["username"].ToString();
password = Request.Form["password"].ToString(); 

if (connection.State == ConnectionState.Closed)
{
connection.Open();
}

try
{
using (command = new SqlCommand(getsqlstring(), connection))
{

reader = command.ExecuteReader();
while (reader.Read())
{
if (username == reader["uorgid"].ToString() && password == reader["password"].ToString())
{
flag = true;
Session["username"] = username.ToString();
Response.Redirect("~/account/home.aspx",false);
}
}
if (flag == false)
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Username / Password Not Match');", true);
}
}
}
catch (ThreadAbortException)
{

throw;

}
finally
{
connection.Close();
command = null;
}

}

public string getsqlstring()
{
sqlstring ="select distinct ud.uorgid,ud.password,us.compcode from user_details ud,user_security us where ud.uorgid=us.userid";
return sqlstring;
}


where i need to improve in this coding
Posted
Updated 30-Dec-14 21:43pm
v2

1. Never inject user's inputs directly into sql statement due to risk of SQL Injection[^], read: Validating (Check) Username and Password from database in ASP.Net[^]
2. Never store password as plain text, read: A Beginner's Tutorial for Understanding and Implementing Password Hashing and Salting[^]
3. Last but not least, do comment your code.
 
Share this answer
 
v2
For improving coding stander's following basic things keep in your mind 

1. You are not writing any school / collage assignment you are developing some kind of product so think about the client expectation’s, think about the end user what kind of things they can be face.
2. Think about unit test case and plan validations and end user messages.
3. Think for other developer and long term maintenance, put necessary commenting in the code as required that will be help for other team members and also to you at the time of maintenance or customization.
4. Search some kind of coding stander on the internet, think about variable and function name declaration and code blocks make it understandable, use Pascal and camel casing.
5. Always write consistent and understandable flow of code.
6. Think about the re-usability and short line of code.
7. Think about performance of application.
8. Search sample code on the internet and review / compare with your code what is the difference between both if possible discuss with your seniors also.
9. Coding stander can be improve day by day not in a day it is some kind of habit and practice.

for more please check following links


http://msdn.microsoft.com/en-us/library/ms229042.aspx[^]


http://blogs.msdn.com/b/brada/archive/2005/01/26/361363.aspx[^]


http://msdn.microsoft.com/en-us/library/ff926074.aspx[^]


http://csharpguidelines.codeplex.com/[^]


http://www.amazedsaint.com/2010/11/top-6-coding-standards-guideline.html[^]


http://weblogs.asp.net/lhunt/CSharp-Coding-Standards-document[^]


http://weblogs.asp.net/lhunt/CSharp-Coding-Standards-document[^]


http://www.dofactory.com/reference/csharp-coding-standards[^]


Code Review Checklist and Guidelines for C# Developers[^]

C# Coding Standards and Best Programming Practices[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900