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.
-
Possible duplicate of stackoverflow.com/questions/1944501/sql-formatter-using-cSergey Vedernikov– Sergey Vedernikov2011-03-02 06:32:29 +00:00Commented Mar 2, 2011 at 6:32
-
Why develop when its already available? You might want to look at dpriver.com/products/sqlpp/ssms_index.phpMayank– Mayank2011-03-02 06:34:28 +00:00Commented Mar 2, 2011 at 6:34
Add a comment
|
2 Answers
Comments
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
Greg
Use Stored Procedures for what?
Jeremy Foster
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.