A C++ .Net example using parameters


	SqlCommand1->CommandType = CommandType::Text;
	SqlCommand1->Parameters->AddWithValue("@Type", Convert::ToString(Type));
	SqlCommand1->Parameters->AddWithValue("@LocationId", Convert::ToString(LocationId));
	SqlCommand1->Parameters->AddWithValue("@EventDateTime", EventDateTime->ToString("s"));
	SqlCommand1->Parameters->AddWithValue("@TagId", Convert::ToString(TagId));
	SqlCommand1->Parameters->AddWithValue("@TagScore", Convert::ToString(TagScore));
	SqlCommand1->Parameters->AddWithValue("@SourceId", SourceId);

	SqlCommand1->CommandText = "DELETE FROM tblMyTable WHERE Something = @LocationId";
	SqlCommand1->ExecuteNonQuery();

	SqlCommand1->CommandText = "INSERT INTO tblMyTable (	\
							   Added,					\
							   Type,					\
							   LocationId,				\
							   EventDateTime,			\
							   TagId,					\
							   TagScore,				\
							   SourceId					\
							   ) VALUES (				\
							   0,						\
							   @Type,					\
							   @LocationId,				\
							   @EventDateTime,			\
							   @TagId,					\
							   @TagScore,				\
							   @SourceId				\
							   )";
	SqlCommand1->ExecuteNonQuery();

 

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.