Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 35

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

926 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