I am trying to save this Swedish string "120918_demo_öar.jpg" to MySQL database. Strangely, the value that is getting stored in the database is "120918_demo_o¨ar.jpg"
Initially, I thought this was a MySQL issue, but found out that that was not the case.
In code, I get this string "120918_demo_öar.jpg" by parsing XML stored in an SQL Server Database table. The string is stored to a variable named imgName
If I do,
imgName == "120918_demo_öar.jpg", it gives false and
imgName.Equals("120918_demo_öar.jpg") also gives false
I have no idea what the issue is. Please help
Thanks in advance
Vivek
Related
I keep getting this error "Input string was not in a correct format" when I'm trying to insert a record with dollar amounts into SQL DB.
I am using C#, Windows Forms Application. In my form, I have a textbox named "quote1". In the DB table, I have a column named "quoteAmount1" DataType "Decimal(8,2) Allow Nulls.
I'm inputting 1300.00 in the textbox then using the following parameter for that textbox to insert into the table:
cmd.Parameters.Add("#quoteAmount1", SqlDbType.Decimal).Value = Convert.ToDecimal(quote1.Text);
Can someone let me know if this is, in fact, the wrong format?
Thank you for any assistance.
Discovered the actual problem. The parameter was correct. I had 2 additional textboxes for dollar amounts that were null and that is what caused the issue. I had to write an if/else statement to catch the null and use DbNull.Value for those that were left blank.
I want to get strings from my App_resource programmatically because I get from the DB a keyword with the name of the string in the app_resource mlbRes.
I have a stored procedure that indicates what the user should do next, sending a string that corresponds to a string in my app_resources file. I can do it with a switch, but that will only complicate my code.
As you can see in the following screenshot, I've tried different approaches, but none worked so far.
screenshot
Can anyone point me out what I'm doing wrong?
Thanks in advance.
Use this Syntax Here mlbRes is your resource file name
string value= Resources.mlbRes.ResourceManager.GetString("StringName");
I've got the error:
INPUT STRING WAS NOT IN A CORRECT FORMAT
when running the code below.
So what do you think here is the error? How will I format the date in the DateTimePicker to store properly in MySQL database?
Here is my code (I included only the relevant code which I think is the error):
cmd.Parameters.AddWithValue("#Rdate", _order.dateTimePicker_Requested.Value.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("#Ndate", _order.dateTimePicker_Needed.Value.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("#CodeDate", Convert.ToDateTime(DateTime.Now).ToString("yyyy-MM-dd hh:mm:ss"));
Unless your MySQL columns are strings (which they shouldn't be), you should be passing actual dates as parameters.
Don't call .ToString().
You should set :
string.Format("{0:yyyy-MM-dd}", your_date);
Hope this helps!
If your variable represents datetime value then its no need to convert it to string it automatically mapped with MySQL column type and if it still not work then reply.
I will post with some code that will convert datetime to proper so that it would mapped with column.
Thank you.
I have a C# application over MySql, using MySQL Connector; I'm trying to make a
DataReader request, the query executes fine, however, when trying to access a DateTime field, i'm getting MySqlConversionException {"Unable to convert MySQL date/time value to System.DateTime"}
this is the prototype
if (dr != null && !dr.Read()) return;
sesion.Id = Convert.ToInt32(dr["id"]);
sesion.Usuario = Convert.ToInt32(dr["usuario"]);
sesion.Estado = Convert.ToByte(dr["estado"]);
// doesn't work
sesion.FchCreacion = Convert.ToDateTime(dr["fch_creacion"]);
Any suggestions?
Thanks in advance
This error sometimes occurs if you have zero datetime values in your MySQL database (00/00/0000 00:00). Try adding this to the end of your connection string:
Allow Zero Datetime=true
There are a few potential gotchas when converting between MySQL dates/times and .NET DateTimes, but there's a useful section in the MySQL documentation with advice on how to handle the issues.
I'd suggest it may be a culture specific error - is the applicaiton on the same server as the DB, and do they have the same culture settings?
Also, is the column definitely a datetime in MySQL?
It could also be a DBNull value.
I'd like to be able to append some data to a binary field in a MS SQL 2005 server from C# without reading the original data, concatenating it, and then setting it all back.
Is this possible?
Cheers!
Steve
I don't know if this option exists in MSSQL 2005, but if someone is searching for appending info into varbinary(max) in MSSQL2008 it can be done like this:
UPDATE [dbo].[Files] SET [FileContent].WRITE('0x',NULL,0)
WHERE Id = 1
Hope this will help someone.
Read about the UPDATETEXT sql statement at http://msdn.microsoft.com/en-us/library/3517w44b.aspx. The Msdn article contains example code that appends binary data to a blob in the StorePhoto method.
Well, I don't know for a BLOB, but for text you can do this:
UPDATE tablename SET columnname=concat(columnname,' my extra text');