Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8808711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:41:26+00:00 2026-06-14T02:41:26+00:00

I am using dateTimePicker to collect date from user in a windows form to

  • 0

I am using dateTimePicker to collect date from user in a windows form to insert in SQL Server Database but when i debug it it says “connot convert dateTime into string” here is the code

string Agent = FieldAgentCombo.Text;
            string Query = "INSERT INTO Comittment(Date,Field_Staff_Date,Detail,Priority,company_name,Name) values('" + Client + "','" + Agent + "','" + Date + "','" + FieldStaffDate + "','" + Detail + "','" + Priority + "')";

            SqlCommand cmd = new SqlCommand(Query, conn);

            int status = cmd.ExecuteNonQuery();
            if (status > 0)
                MessageBox.Show("record inserted");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:41:27+00:00Added an answer on June 14, 2026 at 2:41 am

    Your code is vulnerable to SQL injection. I would recommend you using parametrized queries. Also in your SQL query you seem to have mixed the parameters. Make sure they are matching. For example:

    // load the values that you want to insert into standard .NET types
    DateTime date = ...
    DateTime fieldStaffDate = ...
    string detail = ...
    string priority = ...
    string companyName = ...
    string name = ...
    
    // now connect to the database to execute the SQL query
    using (var conn = new SqlConnection(ConnectionString))
    using (var cmd = conn.CreateCommand())
    {
        conn.Open();
        cmd.CommandText = 
        @"INSERT INTO Comittment(
              Date, 
              Field_Staff_Date, 
              Detail, 
              Priority, 
              company_name, 
              Name) 
          VALUES (
              @Date, 
              @Field_Staff_Date, 
              @Detail, 
              @Priority, 
              @company_name, 
              @name)";
    
        cmd.Parameters.AddWithValue("@Date", date);
        cmd.Parameters.AddWithValue("@Field_Staff_Date", fieldStaffDate);
        cmd.Parameters.AddWithValue("@Detail", detail);
        cmd.Parameters.AddWithValue("@Priority", priority);
        cmd.Parameters.AddWithValue("@company_name", companyName);
        cmd.Parameters.AddWithValue("@name", name);
    
        cmd.ExecuteNonQuery();
    }
    

    This way the query is no longer vulnerable to SQL injection and in addition to that ADO.NET will take care of properly formatting the .NET types into the corresponding SQL types so that you don’t need to be doing any string parsing and date manipulations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using VB.NET I want to display the date in datetimepicker from the database. Code.
Using SQL Server 2000 dtptime - datetimepicker (Format: Custom Format(HH:mm) Query insert into table1
I'm using a DateTimePicker in a form and then showing the date and time
How can I add a DateTimePicker to a User Form using VBA code. Similar
I am using a datetimepicker from jQuery, and when I select a date from
Using SQL Server and VB6 Table1 Date Time 20090801 060000 20090802 162000 Date Format:
I'm using C# .NET and I have a Windows Form with a DateTimePicker. My
I'm have a Windows Form with 2 datetimepicker controls: one for date and a
I am using DateTimePicker with Australian date formatting set (dd/mm/yyyy) The problem is when
How can i post date using jquery?I cam using jquery datetimepicker.i got the date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.