MCV Writing to Database, Getting Error [duplicate] - c#

This question already has answers here:
error, string or binary data would be truncated when trying to insert
(19 answers)
Closed 5 years ago.
I trying to write to a database, I have it connected, but I keep getting this
Error:
SqlException: String or binary data would be truncated.
What is causing it and How do I fix it so I can write to the database?

It sounds like the data you are trying to commit to the database is larger than the allocated size for that field. As an example, you are trying to commit 50 characters to a field but the field is only allocated 10 characters. Check the data you are commiting and the size allocation of the field in the database.

Related

What datatype in C# should I use if mapping a database column of type Timestamp? [duplicate]

This question already has answers here:
What does a timestamp in T-Sql mean in C#?
(4 answers)
Closed 4 years ago.
My client is using Insight.Database for SQL Server ORM, using C# as the client. I have encountered a SQL Server 2017 database datatype 'Timestamp' and I am unsure what the C# entity type should be? I have downloaded the code for the Insight.Database and have globally searched for Timestamp, but results are empty.
Any ideas what datatype in C# would best represent a SQL Server Timestamp datatype?
It would be a byte array as that's what you'd use for varbinary.
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-data-type-mappings

Field sudden increase [duplicate]

This question already has answers here:
Identity increment is jumping in SQL Server database
(6 answers)
Closed 6 years ago.
I have a table in EntityFramework that has a field named by ID,
this field is primary key and is Identity.
when i add records into this table, this field value increases per recor, after adding several records, this value suddenly increases
For example, increased from 90 in 1010
While no transaction has been unsuccessful.
what is the problem?
If you are using Azure SQL this can just happen. We had it happen a few times. It is just the nature of how Azure sql works.
See this question Windows Azure SQL Database - Identity Auto increment column skips values it goes into a detailed explanation for a case very similar to yours

Detecting and replacing all smilies in a string [duplicate]

This question already has answers here:
Mysql server does not support 4-byte encoded utf8 characters
(8 answers)
Closed 7 years ago.
I have a integration with facebook and have notice that thay sends for example u+1f600 that is called a grinning face. When I try to store this in the MySQL Text field I get Server does not support 4-byte encoded so a fast solution is to remove all these special chars from the string.
The question is how? I know about the u+1f600 but I suspect that there could be more of them.
Consider switching to MySQL utf8mb4 encoding... https://mathiasbynens.be/notes/mysql-utf8mb4

How to prevent oracle from converting empty strings to null [duplicate]

This question already has answers here:
Why does Oracle 9i treat an empty string as NULL?
(10 answers)
Closed 9 years ago.
I have successfully converted an existing app's database from SqlServer to Oracle.
Everything works fine, but empty strings.
The app normally stores empty strings into the not null nvarchar2 fields which Oracle silently converts them to null and causes the following error:
ORA-01400: cannot insert NULL
Is there any workaround for this?
Note: I'm using Oracle Managed Driver ODP.NET + NHibernate Castle Active Record
you can use nvl(column_name,'')
Good Luck

What are these data type of characters? [duplicate]

This question already has answers here:
Convert any object to a byte[]
(12 answers)
Closed 7 years ago.
I did a select statement in sql and 1 of the column return me this.
There is a need to query from that sql column, but as this is an existing system, I can only try and error.
From the characters, I have already confirmed if the numbers inside is 0015, I should get 15.
Problem is as you can see above, it contains more than one number, and I have to compare the numbers.
Using SQL Server and C# programming, can some1 guide me on how to retrieve these individual numbers in sql server as well as the data type in C#
In C#, you can directly assign ASCII codes to char. So, for instance,
char c = (char)0x0041;
will assign character repesented by 0x0041, which in this case is 'A', directly to c. You can later convert to string, if necessary, by executing
string s = new string(c);

Categories