Hi,
I have inserted Data into Table into Name filed with special characters in between name.For Example:Chaitan'ya.When iam trying to retriev the Data with that name.Iam getting exceptions.Please Help WithThsi.I want a query to retriev the Data
Thank You
Loading

Roei BarRank #1,271 · 1.4K reputationPosted Oct 2, 2009, 1:04 AM EDT
what you can try todo is for each line you read you will run in all returned columns
and run this command
public static string ReplaceEscapeChars(string str) { //If the string is null if (str == null) return str; //If the string is empty if (str == "") return str; //Replaces single quote (') with two (2) single quotes ('') //solves the problem of inserting, updating or selecting a text with single quote (') str = str.Replace("'", "''"); return str; }this will make the returned text valid for you to select
use for exmaple SQLReader:
private static void ReadOrderData(string connectionString) { string queryString = "SELECT OrderID, CustomerName FROM dbo.Orders;"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); // Call Read before accessing data. while (reader.Read()) { Console.WriteLine(String.Format("{0}", ReplaceEscapeChars(reader[1]))); } // Call Close when done reading. reader.Close(); } }Chaitanya Reddy Vonaja33 reputationPosted Oct 2, 2009, 1:25 AM EDT