Concatinate an sql statement is a bad approch (Security problem), your database will be an easy target of the Sql injections.
I suggest you use a stored procedure to add the or modify the data you want, and use SqlParameters to send the inputs from the user interfaces.
May help : How to create stored procedure
Here's a code example to show you how to call the stored procedure with parameters using C#
//The method that call the stored procedure
public void AddComment()
{
using(var connection = new SqlConnection("ConnectionString"))
{
connection.Open();
using(var cmd = new SqlCommand("storedProcedure_Name", connection) { CommandType = CommandType.StoredProcedure })
{
cmd.Parameters.AddWithValue("@CommentFrom", commandFrom);
cmd.Parameters.AddWithValue("@CommentTo", commentTo);
//...And so on
cmd.ExecuteNonQuery();
}
}
}
A example on how to create a stored procedure
CREATE PROCEDURE storedProcedure_Name
-- Add the parameters for the stored procedure here
@CommentFrom nvarchar(255) = NULL,
@CommentTo nvarchar(255) = NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO Comments (CommentFrom, CommentTo) VALUES(@CommentFrom, @CommentTo)
END
GO