Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-11-18
7
Medium Priority
?
78 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 30

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 66

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 52

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
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 

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 30

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 1000 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 52

Accepted Solution

by:
Vitor Montalvão earned 1000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

688 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