Click here to Skip to main content
15,891,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a data table in Visual Basic which contains rows of data that are called enclosed in quotations.

| "example" | "example" | "example" | "example" |

I would ideally like to remove the quotation marks as I currently have a SQLBulkCopy that is copying in the quotations also.

If anyone could tell me how to remove these then that would be great!
Posted
Comments
_Vitor Garcia_ 25-Jun-13 12:31pm    
You could yourvar.Replace(Chr(34), "") or yourvar.Replace("""", "")

1 solution

Assuming you are using Microsoft SQL Server since you mentioned SQLBulkCopy.

To remove quotes from an already existing data, add a function to the database then use that function to fixup the columns containing quotes. If the data is not yet in an SQL Server database, then your VB .NET program should use the String.Replace method to remove the quotes before inserting new rows into the database table as stated in VitorHugoGarcia's comment above.

Add a new function to your SQL Server
SQL
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION RemoveQuotes 
(
	@str varchar(800)
)
RETURNS varchar(800)
AS
BEGIN
Declare @x int=1;
Declare @strTemp varchar(800);
Set @strTemp=@str;
WHILE @x>0
BEGIN
	SELECT @x=CHARINDEX(CHAR(34),@strTemp,@x)
	if @x>0
	BEGIN
		SELECT @strTemp=STUFF(@strTemp,@x,1,'')		
	END
END
Return @strTemp
END


Execute an UPDATE statement using the RemoveQuotes function
SQL
Update YourTableName 
Set col1=RemoveQuotes(col1),col2=RemoveQuote(col2),RemoveQuotes(col3),col2=RemoveQuote(col4)
 
Share this answer
 
v4
Comments
IanMac91 26-Jun-13 7:33am    
I ideally need to do this before the SQLBulkCopy as it is not currently copying over to the SQL Table because the data types don't match ect.
Mike Meinz 26-Jun-13 9:24am    
I am not sure if you are asking another question or making a statement. If you are asking a question, then the answer is use the example in Solution 1 and execute an SQL UPDATE statement on your source table before doing the SQLBulkCopy.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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