1

Anyone have a good C# method for taking a T-SQL command and formatting it according to some standard? SQL strings are often very ugly and I spend a good deal of time cleaning them up. There's not a good standard format as far as I know, but as long as strings are consistent I wouldn't care too much.

2

2 Answers 2

0

Here you go: http://blogs.msdn.com/b/gertd/archive/2008/08/21/getting-to-the-crown-jewels.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

Use Stored Procedures.

//Stored Procedure name is ADDCustomer_sp
SqlCommand cmd = new SqlCommand("ADDCustomer_sp", con);

cmd.CommandType = CommandType.StoredProcedure;

SqlParameter Name = new SqlParameter("@CusName", SqlDbType.NVarChar, 50);
Name.Value = TextBox1.Text;
Name.Direction = ParameterDirection.Input;
cmd.Parameters.Add(Name);

cmd.ExecuteNonQuery();

2 Comments

Use Stored Procedures for what?
Sorry, misunderstanding. I don't mean that the SQL syntax in my program is ugly and would be helped by putting it behind a sproc. I mean that when a colleague gives me a big SQL statement and says, "Can you tell me how I would do such and such?" I have to spend 15 minutes cleaning up the SQL so I can understand what's going on. It may seem like a nit pick, but I think good and consistent syntax is a big time saver in the work place. I like to put the primary keywords (i.e. SELECT, FROM, WHERE, ORDER BY) on a new line and indent JOINs and extra WHERE clauses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.