Solved

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

Posted on 2016-11-18
7
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 28

Expert Comment

by:Pawan Kumar
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 50

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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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 28

Assisted Solution

by:Pawan Kumar
Pawan Kumar 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 50

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mssql 7 32
VM SQL server license. 1 67
SQL Simple Query Taking a Very Long Time 11 37
SQL Server replace between tags 6 29
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

751 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