asp.net turkish character issue - asp.net

I have a Turkish character problem. If my search string contains "İ", it doesnt return the existing data. When I do select statement below in MSSQL TOOL, It works but when I call the same select statement in ASP.NET , it doesnt work.
here is the select
select * from product where name like N'%GALVANİZ%'
this works in mssql tool and returns the expected data rows. but it doesnt return any data when called in asp.net
how can I get it to return data in asp.net ?

If you're using Turkish characters make sure that your column is nchar or nvarchar.
Then if you're having problems fetching it at the asp.net side try to change it's encoding to "windows-1254" with Encoding.GetEncoding("windows-1254")

Related

ASP.NET Website display wrong data

I built a web application using ASP.NET, data stored at SQL Server 2008.
The application is running ok, but once a couple of day the application displays wrong data and i get error when i enter some pages. system return to normal work after 5 minutes by it self.
can someone give a clue what is the problem?
I'm getting error on lines which try to take data from retrieved DataTable:
like:
txtbx_contact_fullname.Text = dt_contact.Rows[0]["Contact_Fullname"].ToString();
or
lbl_Creation_datetime.Text = dt_YC_Last_Transaction.Rows[0]["Creation_datetime"].ToString();
usually these lines works perfect, and there is no reason that the datatable will return empty.
the error i get is:
Column 'xxxxx' does not belong to table.
The Query that retrieve the data is:
SELECT [Request ID],[Creation Date],[Request Status],[Contact Fullname],[Start Date],[Start Time],[End Date],[End Time],[Work Mode],[Comments],[HPM Points],[FA Points]
FROM dbo.vw_All_Requests
WHERE [Request Status] = #YellowCard_Status
ORDER BY [Creation Date] DESC
From some reason some columns do not get back..
txtbx_contact_fullname.Text = dt_contact.Rows[0]["Contact Fullname"].ToString();
lbl_Creation_datetime.Text = dt_YC_Last_Transaction.Rows[0]["Creation datetime"].ToString();
you column name in asp.net code has _ for example full_name but in sql query it does not have _, i don't know you've assigned names to your datatable or not but give attention to this issue ...
if you code is correct. you are calling Creation_datetime from .NET code, but in SQL you have no such column, what you do have is a Creation date only (from your SELECT query).
so, to fix your problem, all you need to do is change
dt_YC_Last_Transaction.Rows[0]["Creation_datetime"]
to
dt_YC_Last_Transaction.Rows[0]["Creation_date"]
after the issue is fixed, you should learn a better way to query the database using explicit names, for example, using objects instead calling the string value... You should learn a bit of Entity Framework and Linq, it will improve your code a lot.

ASP - Struggling with date format (in WHERE clause) when fetching records from MS Access DB

In the process of moving an existing (and previously working) site from Windows Server 2003 to Server 2008, jumping from IIS6 to IIS7, I have come across this oddity:
OpenSQL("SELECT * FROM bookings WHERE apartment_id = '" & strApartment & "' AND BookDate = #" & SwitchDate(dDate) & "#")
When run, the above SQL script only returns rows if there is no leading zero in the date. For example, it will return rows if the date is 10/01/2010. But it will not return rows if the date is 01/01/2010. Instead I get this error:
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
I'm not very familiar with ASP at all (in this instance running VB I believe, though it me be classic ASP - I'm not sure how you tell?). But this is a very simple request and I can't understand what is going on. I have tried removing the switchdate function (which removes all leading zeros), and playing with the syntax, all to no avail.
The Access DB holds the records in the format 01/01/2001.
While it is true that the ACE and Jet database engines treat ambiguous #xx/yy/zzzz# date literals as mm/dd/yyyy they also accept the unambiguous formats yyyy-mm-dd and yyyy/mm/dd so your best solution would be to update your SwitchDate() function to return one of those formats.

How to convert Number Datatype to Text Datatype - ODBC Query - C#

I am developing a Windows Forms Application in C# with 2.0 being the underlying .Net Framework. I use .Net Framework Data Provider for ODBC in order to connect to a specific access database.
I have a field say "NumberColumn" with 'Number' datatype & another field say "StringColumn" with 'Text' datatype in one of the tables present in the database. I have to concatenate the values present in the two fields in this format ("StringColumn-NumberColumn").
I tried using the convert function "CStr" in the query to convert the number column and append with the string column but am getting an exception "Invalid scalar function CStr".
Presently, am doing this concatenation in the DataTable level which I feel is expensive considering the huge amount of data. How could I achieve the concatenation in the specified format while querying the data?
I don't think you mention the database but I would expect something like
select StringColumn || '-' || cast( NumberColumn as varchar ) from table
may do what you want, but that becomes database dependent.
If you are saying its access, and you are using the jet provider then I would think that
select StringColumn + '-' + {fn cstr( NumberColumn )} from table
Would work. At least it does directly to the MS Access ODBC driver

SQL Server & ASP .NET encoding issue

my page has utf-8 meta element added + sql server encoding is also utf. However when I create record and try to issue SELECT statement with condition that contains POLISH characters like 'ń' , I see no results. Any ideas what am I missing?
ALSO Sql management studio shows result with POLISH characters , but I don't trust it.... I guess something is wrong with putting record into database...
Or how can I troubleshoot it?
Thanks,Paweł
I had the same issue, and I solved it by prefixing the text in the WHERE clause with "N".
For example, I have a table 'Person' containing a bit over 21,000 names of people. A person with the last name "Krzemiński" was recently added to the database, and the name appears normal when the row is displayed (i.e., the "ń" character is displayed correctly). However, neither of the following statements returned any records:
SELECT * FROM Person WHERE FamilyName='Krzemiński
SELECT * FROM Person WHERE FamilyName LIKE 'Krzemiń%'
...but these statements both returned the correct record:
SELECT * FROM Person WHERE FamilyName LIKE 'Krzemi%'<br>
SELECT * FROM Person WHERE FamilyName LIKE 'Krzemi%ski'
When I executed the following statement:
SELECT * FROM Person WHERE FamilyName LIKE '%ń%'
I get all 8900 records that contain the letter "n" (no diacritic), but I do not get the record that contains the "ń" character. I tried this last query with all of the Polish characters (ąćęłńóśźż), and all of them except "ó" exhibit the same behavior (i.e., return all records with the lower-ASCII equivalent character). Weirdly, "ó" works as it should, returning only those records with an "ó" in the FamilyName field.
In any case, the solution was to prefix the search criterion with "N", to explicitly declare it as Unicode.
Thus, the following statements:
SELECT * FROM Person WHERE FamilyName LIKE N'%ń%'
SELECT * FROM Person WHERE FamilyName=N'Krzemiński'
...both return the correct set of records.
The reason I was confused is that I have MANY records with weird diacritics, and they all return the correct records even without the "N" prefix. So far, the only characters I've found that require the explicit "N" prefix are the Polish characters.
According to this (Archived) Microsoft Support Issue:
You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server
simply use nvarchar instead of varchar as the datatype of the column saving the record.

HTML/ASPX textbox to store non-english characters to SQL database

I have this textbox on an .aspx page, which when submitted it stores whatever typed in the textbox into a nvarchar column in MS SQL 2005.
It works fine, until you try putting chinese characters.
These characters are converted to question marks (?) in the database.
How do you store non-english characters from a <input type="text"> to database?
The main thing would be to ensure that every step of the pipeline supports international characters; i.e. - at what point do you first see "?" ? In the aspx code? Or only once it gets into the database table?
The web page should already be using an encoding such as UTF8, so that should be OK - but what data type are you using at the database? It would need to be nchar/nvarchar(n)/nvarchar(max) (or ntext on older versions of SQL Server).

Resources