Click here to Skip to main content
15,896,606 members

Single quote issue in C# dataset

sai.2012 asked:

Open original thread
I am running oracle query and getting the data storing it in dataset(dsDataSet)
STEP 2 :Copying it to datatable.
dtAEDetails= dsDataSet.Tables[0].Copy();)
Step 3 : storing the datatable into access database.

I am having issue in datatable, one field Desc1 in datatable having single quote(ex:
'SCHOLAR'S EDGE THE AGGR P'


The below code is inserting datatable into access database.
if datatable rows >0 then inserting into access database.
DESC1 field is having single quote , how to replace single quote with double quote before insert into database.
if (dtAEDetails.Rows.Count > 0)
               {
                   //Set up the params
                   foreach (DataRow drAEDetails in dtAEDetails.Rows)
                   {
                       sInsertValues =
                            "'" + drAEDetails["OFFICE"].ToString() + "','"
                                + drAEDetails["AE"].ToString() + "','"<pre> if (dtAEDetails.Rows.Count > 0)
               {
                   //Set up the params
                   foreach (DataRow drAEDetails in dtAEDetails.Rows)
                   {
                       sInsertValues =
                            "'" + drAEDetails["OFFICE"].ToString() + "','"
                                + drAEDetails["AE"].ToString() + "','"
                                + drAEDetails["SETDATE"].ToString() + "','"
                                + drAEDetails["ACCT"].ToString() + "','"
                                + drAEDetails["SHORT"].ToString() + "','"
                                + drAEDetails["BS"].ToString() + "','"
                                + drAEDetails["SHARES"].ToString() + "','"
                                + drAEDetails["DESC1"].ToString()+ "','"
                                + drAEDetails["PRICE"].ToString() + "','"
                                + drAEDetails["PRINC"].ToString() + "','"
                                + drAEDetails["GROSS"].ToString() + "','"
                                + drAEDetails["STAND"].ToString()  + "','"
                                + drAEDetails["NET"].ToString()  + "','"
                                + drAEDetails["NEWNET"].ToString() + "','"
                                + drAEDetails["AECHG"].ToString()+ "','"
                                + drAEDetails["BONUS"].ToString()+ "','"
                                + drAEDetails["BT"].ToString() + "','"
                                + drAEDetails["CANCEL"].ToString() + "','"
                                + drAEDetails["TRANSCODE"].ToString() + "','"
                                + drAEDetails["ORDERSORT"].ToString() + "','"
                                + drAEDetails["REALGR"].ToString() + "','"
                                + drAEDetails["ANNUITYNET"].ToString() + "','"
                                + drAEDetails["RECORDID"].ToString() + "','"
                                + drAEDetails["USER_CODE_1"].ToString() + "','"
                                + drAEDetails["USER_CODE_7"].ToString() + "'";


                       insertAEdetails.ParmValue = sInsertValues;
                       insertAEdetails.InsertIntoAccess();

how to replace single quote into double quote in desc field and store it to dataset, after replacing I want to store it into datatable . how to do it.

Please guide me.

Thanks

What I have tried:

I thought of replacing in query , but my colegue said it's easy in code.

can you please give me idea.
Tags: C# 3.5

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900