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 c开发者_运维知识库are too much.
Here you go: http://blogs.msdn.com/b/gertd/archive/2008/08/21/getting-to-the-crown-jewels.aspx
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();
精彩评论