第一关:STOP串联起来你的SQL代码!这是针对SQL注入攻击的邀请,它对性能也非常不利 - 使用参数化查询代替。
如果你这样做 - 你不会有日期时间/串转换问题,无论问题.....
其次:约会,只DateTime
“安全”的格式在SQL Server是YYYYMMDD
- 没有任何破折号 - 只有这种格式保证它可以在任何SQL Server上运行,无论您的语言,地区和dateformat设置如何。
第三。如果要执行存储过程 - 我会建议使用这种方法:
System.DateTime myDate = default(System.DateTime);
myDate = DateTimePickerPrint.Value;
using (SqlConnection con = new SqlConnection(your-connection-string-here))
using (SqlCommand cmd = new SqlCommand("dbo.Save_Quotation_Bookshop", con))
{
// tell ADO.NET it's a stored procedure (not inline SQL statements)
cmd.CommandType = CommandType.StoredProcedure;
// define parameters
cmd.Parameters.Add("@QuotationNo", SqlDbType.VarChar, 50).Value = txt_QutationNo.Text;
cmd.Parameters.Add("@CustomerCode", SqlDbtype.VarChar, 25).Value = txt_CusCode.Text;
cmd.Parameters.Add("@SaleDate", SqlDbType.DataTime).Value = myDate;
// open connection, execute stored procedure, close connection again
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
不要使用为嵌入式SQL语句 - 告诉你执行存储过程ADO.NET,提供参数 - 你完成了!
thnx用于回复,其工作方式是通过删除EXEC ADO.NET,并执行完整的ADO.NET – las