Solved

Why its difficult to  Insert the Bit and date time value in sql Database

Posted on 2016-11-18
7
30 Views
Last Modified: 2016-11-18
Hi Experts ,

Why it's so hard to insert the Bit and date time value on sql database always gonna to Error . What are the things I need to consider for this Data value ? Am working on C# using sql server for database

Thanks in Advance Experts
0
Comment
Question by:karthik80c
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
ID: 41892948
Can you please post what exactly are you doing.? We shall try to fix the issue.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41892954
Don't know, and we won't be able to answer you question without you posting for us the schema of the table, query you're trying to insert, and maybe a data mockup of these bit and datetime values.

Keep in mind that experts here cannot connect to your data source and run queries, so you'll have to tell us everything we need to know to troubleshoot.
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 41892963
Maybe because you're not using the proper format?
For example, bit only accepts 0 and 1 nor 'T' or 'F' or 'True' or 'False'.
Dates can't be inserted as text, e.g. '12-31-2016' nor as MS Access way: '#12-31-2016#'
1
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:karthik80c
ID: 41892991
Hi Experts


Sorry for not that detailed question . Am trying to insert the date value and bit type value on a database .

Fields
EmailOptOut , data type = bit
CreatedTime , data type = datetime

Query
INSERT INTO tbl (EmailOptOut ,CreatedTime ) value (True,DateTime.Now.toString())

Whenever am trying to any one value alone am getting this error

Error
Date time = > Input string was not in a correct format with DateTime
Bit value => Input string was not in a correct format.
0
 
LVL 17

Assisted Solution

by:Pawan Kumar Khowal
Pawan Kumar Khowal earned 250 total points
ID: 41892996
try..

CreatedTime is of type DateTime and you are passing a string into it.
EmailOptOut is of type Bit and you are passing a string into into it.

INSERT INTO tbl (EmailOptOut ,CreatedTime ) value (1,DateTime.Now)
1
 
LVL 45

Accepted Solution

by:
Vitor Montalvão earned 250 total points
ID: 41892998
Yes, like I said you're formatting it wrong.
Bit accepts only 0 and 1 representing respectively the False and True.
DateTime.Now.toString()) doesn't provide either the correct format for SQL Server engine. Try to reformat it to 'YYYYMMDD HH:MM:SS'.
1
 

Author Closing Comment

by:karthik80c
ID: 41893020
Thanks for all your valuable Efforts Experts
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now