My Excel 2016 doesn't have the DSN drop down list when creating a New Query to connect to an ODBC data source. It only shows the connection string option. How can I get it to show the option highlighted in the second image?
I am able to insert values into my Excel file using c# successfully. But when my column name contains "#" (for example Target_Group#), I get this error:
Unknown column name
But in my Excel the column name should be "Target_Group# "
My insert query is:
string query = "INSERT INTO [Sheet2$] ([Target_Group#]) VALUES('OHMCRWP0')";
I am using OLEDB connections
Hi I am trying to take the amount entered in a text box and save that to a sql database in decimal format. The field in the table is set as decimal 7,2
The amount a user inputs is save to the table. However it rounds the decimal amount. eg. 10.55 saved as 11.00 & 10.45 saved as 10.00
I'm using visual studio 2010 and vb.net
This is the code I'm using to write the content to the database. Any help would be appreciated.
myCommand.Parameters.AddWithValue("customer_contribution", Convert.ToDecimal(CType(Me.FormView1.FindControl("CustomerContributionTextbox"), TextBox).Text))
I've also tried it without the Decimal conversion and end up with the same results.
myCommand.Parameters.AddWithValue("customer_contribution", customer_contribution)
Use # symbol before parameter name. and if you want to specify the parameter's sqldbtype then use the properties of command parameter as per equivalent to decimal type.
Check this:
myCommand.Parameters.AddWithValue("#customer_contribution",
Follow this Configuring Parameters and Parameter Data Types (ADO.NET)
' Add the input parameter and set its properties.
Dim parameter As New SqlParameter()
parameter.ParameterName = "#Price"
parameter.SqlDbType = SqlDbType.Decimal
parameter.Direction = ParameterDirection.Input
parameter.Value = categoryName
' Add the parameter to the Parameters collection.
command.Parameters.Add(parameter)
My MySQL database can store the euro symbol just fine (as I have tested with a native MySQL client (HeidiSQL)). But with the MySQL .NET connector my ASP.NET application is using I can't insert nor read it back from the database: I only get a ? character back. What could be the possible cause?
I would suggest explicitly specifying the encoding in your connection string:
Server=localhost;Database=schema;Uid=foo;Pwd=bar;CharSet=utf8;
It usually resolves most encoding-related issues with MySQL's Connector/NET.
I'd say that MySQL .NET connector sets some collation-related environment variables on connection; compare output of these queries both on HeidiSQL and .NET:
SHOW VARIABLES LIKE "character_set_%";
SHOW VARIABLES LIKE "collation_%";
They all should contain utf8-something. If not, you can alter them at runtime as in the manual.
The following .Net command can encode these for your database, and then decode them into the original symbol...
System.Web.HttpUtility.HtmlEncode()
System.Web.HttpUtility.HtmlDecode()
Presumably you are inserting into the euro sign into a field that is typed as NVARCHAR or you wouldn't be able to insert and retrieve the euro sign correctly with other clients?
Are you using the correct syntax in your SQL statements for inserting and retrieving Unicode data?
To do this you must use the N specifier character before any string which is unicode or it will get silently converted to a single byte encoding and become an unreadable character e.g.
//Inserting Unicode data
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "INSERT INTO SOME_TABLE (someField) VALUES (N'#text')";
cmd.Parameters.Add("text", "Some Unicode Text");
cmd.Connection = conn;
cmd.ExecuteNonQuery();
//Selecting Unicode data
MySqlCommand select = new MySqlCommand();
select.CommandText = "SELECT * FROM SOME_TABLE WHERE someField=N'#text'";
cmd.Parameters.Add("text", "Some Unicode Text");
cmd.Connection = conn;
//Execute your query and process your Results...
I had a similar problem, trying to import data from Sybase 12.5 to MS SQL Server 2005.
Basically MSSQL stores £ and euro signs fine in varchar if they're encoded right, which is great, but what I didn't realise is that Sybase was outputting the data as windows-1252 (western european) and not UTF-8 and this caused data like £ and the euro symbol to get translated by the import programme as '?'. Telling the import programme that the incoming data is encoded as 1252 fixed the issue.
If you encode the output from the DB as 1252 as you're reading it, you should get the right symbols out.
For example:
System.Text.Encoding enc = System.Text.Encoing.GetEncoding(1252);
MySqlDataReader msdr = command.ExecuteReader();
while(msdr.Read())
{
...
string val = enc.GetString(enc.GetBytes(msddr.GetString(mssdr.GetOrdinal("varhcar_field"))));
...
}
Have you correctly set the charset in your output page ?
i.e. something like <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
or charset=iso-8859-15 but not charset=iso-8859-1
I am setting the locale of my .net application via:
string userLocale = Web.Helpers.LocaleHelpers.GetBestRFC3066Locale(this.Context.Request.UserLanguages);
if (userLocale != String.Empty)
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(userLocale);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(userLocale);
}
This works well, so my dates will be displayed in the format based upon the locale i.e.
12/10/2009 for en-gb
and
10/12/2009 for us
However when I persist my dates via LinqToSql I need to store these dates in a common format.
Currently when a U.S. user is running the app the date stored in the DB is in U.S. format and when an U.K. user uses the app, its in a U.K. format.
Any suggestions on how best to achieve this?
Store the date as a datetime value in SQL Server. Then you don't run into a conversion problem.
Brannon has the right solution there. Once you have a variable in a datetime format in SQL you can convert it to other datetime formats using the CONVERT T-SQL keyword