Solved

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

Posted on 2016-11-18
7
74 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 29

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 51

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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 29

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 51

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

623 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