You don't want to do it that way, you'll ant to use command parameters and a parameterized sql query instead (otherwise you open your application up to
SQL Injection[
^] (and that is
bad).
Something like this might point you in the right direction;
DateTime dt = DateTime.Today;
label4.Text = dt.ToString("dd/MM/yyyy");
cn.Open();
using (var cmd = new SqlCommand("insert into Entry(Crnt_Date, Enter_Date, Time_,Name_, Product_, Count_,Amount_) values (@Crnt_Date, @Enter_Date, @Time_,Name_, @Product_, @Count_, @Amount_)"), cn)
{
cmd.Parameters.AddWithValue("Crnt_Date", DateTime.ParseExact(label4.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture));
cmd.Parameters.AddWithValue("Enter_Date", dateTimePicker1.Value);
cmd.Parameters.AddWithValue("Time_", comboBox3.Text);
cmd.Parameters.AddWithValue("Name_", lblName.Text);
cmd.Parameters.AddWithValue("Product_", comboBox1.Text);
cmd.Parameters.AddWithValue("Count_", comboBox2.Text);
cmd.Parameters.AddWithValue("Amount_", textBox1.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Inserted");
}
cn.Close();
To handle possible incorrectly typed dates in the text boxes look into
DateTime.TryParseExact
.
Hope this helps,
Fredrik