المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C# DataBase Application How you do it ?



C# Programming
07-03-2009, 10:51 PM
Hi, have a good day ,

I was wondering , how do you write Database Application With C# ?

I mean what is the your way , what tools do you use and what is your rules ?

--- For me :

1 - All My SqlConnection , DataTable Are in Runtime ( no desing at all )

2 - I write INSERT and update and delete Sql Query Manually , like functions ( even if I have 50 values in INSERT command I wrote them
as paramters

public static void DeletePerson ( string guid )
{
SqlCommand SqlCmd.CommandText ="DELETE FROM persons WHERE guid = @guid";
SqlCmd.Parameters.AddWithValue ("@guid" , guid);
SqlCmd.ExecuteNonQuery();
SqlCmd.Parameters.Clear();
}


3 - I always use paramters .
4 - I always use Transaction ( even for the short one )
5 - I never ever Use Binding Source ( I build one manually )
Like TxtPerson.Text = clsDataTable.Rows[CurrentRecored]["Name"].ToString();

Insted of
TxtPerson.DataBindings.Add("Text" , bindingsource , "name" );
6 - I never use Identity in my database , I generte the last number
manually
SELECT MAX(PersonID) FROM persons
7 - All my tables recored dependes on GUID ( No Guid = No table at all )
8 - I use SQL Query Analyzer ... I hate VS Server Explorer ...
9 - For Complex Search Query
I used some routin's like :
public string[] SearchUserNames = { "Name" , "Age" }; // Added to combobox
public string[] SearchDBNames = { "pName" , "pAge"};


stQuery = "SELECT * FROM persons";
int isAnd = 0;

if (CheckName.Checked)
{
stQuery += " WHERE " + SearchDBNames[combobox.SelectedIndex].ToString();
isAnd++;
}
if (CheckAge.Checked)
{
if (isAnd != 0)
{
stQuery += " AND ";
}
else
{
stQuery += " WHERE ";
}
stQuery += SearchDBNames[combobox.SelectedIndex].ToString();
isAnd++;

}



I want to hear from you ... what is yours ?
I am doing right ?


Thank you , for time and for your advice ...

I know nothing , I know nothing ...