Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Friday, March 30, 2012

inserted text take the wrong alignment

i try to insert the following string in the database

the red car (driver)

this string save like this

)the red car (driver

i have a problem when inserting string contains special character at the end of the string.

we have arabic and english string like this

???? ????? (R) radial ????

and it appear in reverse like this

???? (R) radial ???? ?????

You need to check the application that is inserting the data specifically the API commands being used. This is not a SQL Server problem per se. The database engine will store the values as passed from the client and doesn't manipulate it on the server. Also, where are you checking the display of the values? It is possible that the tool is doing something based on your language / regional settings. So this could just be a display issue also. Start with verifying the data in the back end tables directly, then your client code and then whatever UI you are using.|||

hello Umachandar,

me and Batool posted this one together

I do import the data into the database through a certain script, but I thought it was an sql problem, because the data were in the correct alignment before inserting, I see them reversed in the tables directly, actually to test this issue I tried to enter data directly into the database so in the cell I press ctrl + Alt + shift to reverse the alignment inside the cell in table, and when I start submitting my data it is reversed.

how could this be a display problem when it's correct in all other applications on my machine

thank you

|||

I believe I've seen funny behavior in Management Studio when you try to display mixed right-left and left-right scripts. (I doubt this is unique to MS.) Can you inspect the binary contents of the strings and see whether it contains what you expect?

Cheers,

|||

You should verify the data first without involving any UI elements into the picture. The reason I say that it could be a display issue is that the tool might be doing something different when reading and displaying the data. This happens for float data type values today. The accuracy of the digits are different from ISQLW and in some cases two values that differ in say the 17th decimal digit will look the same. But this doesn't mean that the values are the same.

So you could write a script or program that does the insert, reads the data back and verifies it using SQL only. This will eliminate the UI from the picture. Additionally, tracing the calls to the server from the UI / tool via Profiler will also help. You can find out if the provider/driver is translating the string based on code page settings. There are just too many variables involved in this. Is it possible to do the following?

1. Post a simple DDL, insert statements and SELECT which shows the behavior (note that you may have to use the appropriate collation and Unicode data type to avoid any character translation)

2. If #1 doesn't work for you, is it possible to post some steps using say a particular UI (like ISQLW or SSMS). Please be clear on how you are inputting the data (open table, script/open table combination) and so on. Schema and data type of the column(s) are important here also. You talk about entering something in a cell - where is this? What UI are you talking about?

Lastly, the configuration of the OS (language/regional settings) may also be a factor and version of SQL Server. So please post those also.

Wednesday, March 7, 2012

Insert Query Problem

hi all i m trying to insert in my datbase this query but it is giving error at the line myCommand.ExecuteNonQuery();

myConnection.Open();
String insertCmd = "insert into CRtable(@.CR_NO, @.Asset_Type, @.PortIDNew, @.SpecialRequest, @.MovePortFrom, @.MovePortTo, @.MoveHardware, @.MoveSoftware, @.AllSelected, @.SpecialSoftwarePort, @.SpecialSoftwares, @.OtherSoftwares, @.FolderName, @.FolderPurpose, @.FolderUserIds, @.FolderRetentionPeriod, @.SpecialAccessOnExistFolder, @.AcessType, @.ExistFolderUserId, @.SpecialAcessOnIntranet, @.InternetUserId, @.MailId, @.HeadSet, @.Requester, @.RequestDateTime, @.Dept, @.PurposeOfCrForm, @.RequestedPort, @.ecode, @.qty, @.process, @.cost_evaluation, @.capital_exp, @.tat)";


SqlCommand myCommand = new SqlCommand(insertCmd,myConnection);myCommand.Parameters.Add("@.CR_NO",crm1);
myCommand.Parameters.Add("@.Asset_Type",StrAssetType2+StrAssetType);
myCommand.Parameters.Add("@.PortIdNew",StrPorts);
myCommand.Parameters.Add("@.SpecialRequest",StrSpecialRequest);
myCommand.Parameters.Add("@.MovePortFrom",txtAssetMovementFrom);
myCommand.Parameters.Add("@.MovePortTo",txtAssetMovementTo);
myCommand.Parameters.Add("@.MoveHardware",StrAssetHardware);
myCommand.Parameters.Add("@.MoveSoftware",StrAssetSoftware);
myCommand.Parameters.Add("@.AllSelected", StrAssetStatus);
myCommand.Parameters.Add("@.SpecialSoftwarePort",StrSpecialSoftwarePort);
myCommand.Parameters.Add("@.SpecialSoftwares",StrSpecialSoftware);
myCommand.Parameters.Add("@.OtherSoftwares",StrOtherSoftware);
myCommand.Parameters.Add("@.FolderName",StrFolderName);
myCommand.Parameters.Add("@.FolderPurpose","");//
myCommand.Parameters.Add("@.FolderUserIds",StrFolderUserId);
myCommand.Parameters.Add("@.FolderRetentionPeriod",StrFolderRetentionDays);
myCommand.Parameters.Add("@.SpecialAccessOnExistFolder","");//
myCommand.Parameters.Add("@.AcessType",StrAcessType);
myCommand.Parameters.Add("@.ExistFolderUserId",StrExistFolderUserId);
myCommand.Parameters.Add("@.SpecialAcessOnIntranet","");//
myCommand.Parameters.Add("@.InternetUserId","");//
myCommand.Parameters.Add("@.MailId","");//
myCommand.Parameters.Add("@.HeadSet","");//
myCommand.Parameters.Add("@.Requester",StrRequest);
myCommand.Parameters.Add("@.RequestDateTime",time);
myCommand.Parameters.Add("@.Dept",StrDept);
myCommand.Parameters.Add("@.PurposeOfCrForm",StrPurpose);
myCommand.Parameters.Add("@.RequestedPort"," ");//
myCommand.Parameters.Add("@.ecode",ecode);
myCommand.Parameters.Add("@.qty",quantity);
myCommand.Parameters.Add("@.process",proces);
myCommand.Parameters.Add("@.cost_evaluation",cost);
myCommand.Parameters.Add("@.capital_exp"," ");//
myCommand.Parameters.Add("@.tat",tat);
try
{
myCommand.ExecuteNonQuery();
}
catch (SqlException er)
{
Response.Write(er.StackTrace);
}

myConnection.Close();
}


the error mwssage is following

Line 1: Incorrect syntax near ')'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near ')'.

Source Error:


Line 182:// try
Line 183:// {
Line 184: myCommand.ExecuteNonQuery();
Line 185:// }
Line 186:// catch (SqlException er)

Source File: c:\inetpub\wwwroot\cr request form\crpreview1.aspx.cs Line: 184

why this is occuring?

The correct structure for an INSERT statement is like this:
INSERT INTO someTable(column1, columns2)VALUES (@.param1, @.param2)
|||hi thanks for ur response but there is another problem actully I am passing some values in a parameter as blank resulting in incorrect formation of my InsertString.
it is be getting build as
"insert ito table values('val1',val2',)
Resulting in Error.But I have to pass these null values depending upon the Requet.Querystring form another page.It can be any value or it can not have any value .what should i do for it?|||hi the command run properly but the values r not inserting in the table .
what will be there.my query is
string insertCmd="insert into CRtable('" + crm1 + "','" + StrAssetType2 + StrAssetType +"','" + StrPorts + "','" + StrSpecialRequest + "','" + txtAssetMovementFrom + "','" + txtAssetMovementTo + "','" + StrAssetHardware + "','" + StrAssetSoftware + "','" + StrAssetStatus + "','" + StrSpecialSoftwarePort + "','" + StrSpecialSoftware + "','" + StrOtherSoftware + "','" + StrFolderName + "','" + null + "','" + StrFolderUserId + "','" + StrFolderRetentionDays + "','" + null + "','" + StrAcessType + "','" + StrExistFolderUserId + "','" + null + "','" + null + "','" + null + "','" + null + "','" + StrRequest + "','" + time + "','" + StrDept + "','" + StrPurpose + "','" + null + "','" + ecode + "','" + quantity + "','" + proces + "','" + cost + "','" + null + "'," + tat + ")";

but no insertion in table.|||

I agree with tmorton , first please make sure you use correct T-SQL syntax in your query. For example if you want to insert a row with some null fields, you should use such query:

insert into mytable(column1,column2,column3) values('val1',null,'val3')

|||

for those string variable, use ' ' for the value

www.cyberxforum.com

|||

ruchipunetha:

hi the command run properly but the values r not inserting in the table .
what will be there.my query is
string insertCmd="insert into CRtable('" + crm1 + "','" + StrAssetType2 + StrAssetType +"','" + StrPorts + "','" + StrSpecialRequest + "','" + txtAssetMovementFrom + "','" + txtAssetMovementTo + "','" + StrAssetHardware + "','" + StrAssetSoftware + "','" + StrAssetStatus + "','" + StrSpecialSoftwarePort + "','" + StrSpecialSoftware + "','" + StrOtherSoftware + "','" + StrFolderName + "','" + null + "','" + StrFolderUserId + "','" + StrFolderRetentionDays + "','" + null + "','" + StrAcessType + "','" + StrExistFolderUserId + "','" + null + "','" + null + "','" + null + "','" + null + "','" + StrRequest + "','" + time + "','" + StrDept + "','" + StrPurpose + "','" + null + "','" + ecode + "','" + quantity + "','" + proces + "','" + cost + "','" + null + "'," + tat + ")";

but no insertion in table.


Again, the correct syntax is:
INSERT INTO someTable(column1, columns2)VALUES (@.param1, @.param2)
Note that I used parameters, and note that there are 2 parts: column names and values to assign to those columns. Do not build a SQL statement like that, from data supplied by a UI. It is insecure.|||

i reckon that used parameters can prevent SQL injection hack..

www.cyberxforum.com

|||

yuan:

i reckon that used parameters can prevent SQL injection hack..


Yes, that's correct.|||i agree with u but the crm1 are string variable not constant i cannot put them in single quoto.

INSERT query gets String data right truncation through ODBC but it works in SQL Server 7?

Hello Helpfull Helpers,
When I try to run an insert query from my Web site I get the following
error...
Error Diagnostic Information
ODBC Error Code = 22001 (String data right truncation)
[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data
would be truncated.
The error occurred while processing an element with a general
identifier of (CFQUERY), occupying document position (701:3) to
(701:73).
...but when I copy and paste the query into SQL Server Enterprise
Manager, the Insert succeeds.
Why does the query work in SQL Server Enterprise Manager but not from
my Web page? The Web page used to work fine.
My System Information:
======================
Windows 2000 Server (Operating System)
Cold Fusion 4.5 Server (Dynamic Web Server)
SQL Server 7.0 (Database Server)
The Query That Fails In The Web Page But Succeeds In Enterprise
Manager:
================================================== ======================
INSERT INTO dboJob(CUID, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
f13, f16, f17, f18, f19)
VALUES(
14036,
'09/17/2004 1:3:7 PM',
0,
'o',
'Testing new limit region functionality',
'Limit region should include cascading city, state or province,
country, and zip.',
'Fully functional.',
'',
'11',
'p',
'',
'',
'3',
'5',
0,
0 )
Table Information (field names have been changed to protect the
innocent):
================================================== ========================
CREATE TABLE [dbo].[dboJob] (
[JOID] [decimal](18, 0) IDENTITY (1, 1) NOT NULL ,
[CUID] [decimal](18, 0) NOT NULL ,
[f1] [varchar] (2) NOT NULL ,
[f2] [datetime] NOT NULL ,
[f3] [datetime] NOT NULL ,
[f4] [money] NOT NULL ,
[f5] [varchar] (1) NOT NULL ,
[f6] [varchar] (100) NULL ,
[f7] [varchar] (3000) NOT NULL ,
[f8] [varchar] (1500) NOT NULL ,
[f9] [varchar] (3000) NULL ,
[f10] [numeric](18, 0) NOT NULL ,
[f11] [char] (1) NOT NULL ,
[f12] [varchar] (200) NOT NULL ,
[f13] [varchar] (64) NULL ,
[f14] [varchar] (1) NOT NULL ,
[f15] [varchar] (1) NOT NULL ,
[f16] [varchar] (1) NOT NULL ,
[f17] [varchar] (1) NOT NULL ,
[f18] [money] NOT NULL ,
[f19] [money] NOT NULL ,
[f20] [datetime] NOT NULL
) ON [PRIMARY]
GO
Thanks,
Nate
I suggest you try the INSERT statement through QA. After the INSERT, check whether the data has been
truncated. Also, read about SET ANSI_WARNING.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"nate" <nathandeneau@.cox.net> wrote in message
news:4630acfb.0409141227.64eb7823@.posting.google.c om...
> Hello Helpfull Helpers,
> When I try to run an insert query from my Web site I get the following
> error...
> Error Diagnostic Information
> ODBC Error Code = 22001 (String data right truncation)
> [Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data
> would be truncated.
> The error occurred while processing an element with a general
> identifier of (CFQUERY), occupying document position (701:3) to
> (701:73).
> ...but when I copy and paste the query into SQL Server Enterprise
> Manager, the Insert succeeds.
> Why does the query work in SQL Server Enterprise Manager but not from
> my Web page? The Web page used to work fine.
> My System Information:
> ======================
> Windows 2000 Server (Operating System)
> Cold Fusion 4.5 Server (Dynamic Web Server)
> SQL Server 7.0 (Database Server)
> The Query That Fails In The Web Page But Succeeds In Enterprise
> Manager:
> ================================================== ======================
> INSERT INTO dboJob(CUID, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
> f13, f16, f17, f18, f19)
> VALUES(
> 14036,
> '09/17/2004 1:3:7 PM',
> 0,
> 'o',
> 'Testing new limit region functionality',
> 'Limit region should include cascading city, state or province,
> country, and zip.',
> 'Fully functional.',
> '',
> '11',
> 'p',
> '',
> '',
> '3',
> '5',
> 0,
> 0 )
> Table Information (field names have been changed to protect the
> innocent):
> ================================================== ========================
> CREATE TABLE [dbo].[dboJob] (
> [JOID] [decimal](18, 0) IDENTITY (1, 1) NOT NULL ,
> [CUID] [decimal](18, 0) NOT NULL ,
> [f1] [varchar] (2) NOT NULL ,
> [f2] [datetime] NOT NULL ,
> [f3] [datetime] NOT NULL ,
> [f4] [money] NOT NULL ,
> [f5] [varchar] (1) NOT NULL ,
> [f6] [varchar] (100) NULL ,
> [f7] [varchar] (3000) NOT NULL ,
> [f8] [varchar] (1500) NOT NULL ,
> [f9] [varchar] (3000) NULL ,
> [f10] [numeric](18, 0) NOT NULL ,
> [f11] [char] (1) NOT NULL ,
> [f12] [varchar] (200) NOT NULL ,
> [f13] [varchar] (64) NULL ,
> [f14] [varchar] (1) NOT NULL ,
> [f15] [varchar] (1) NOT NULL ,
> [f16] [varchar] (1) NOT NULL ,
> [f17] [varchar] (1) NOT NULL ,
> [f18] [money] NOT NULL ,
> [f19] [money] NOT NULL ,
> [f20] [datetime] NOT NULL
> ) ON [PRIMARY]
> GO
> Thanks,
> Nate

INSERT query gets String data right truncation through ODBC but it works in SQL Server 7?

Hello Helpfull Helpers,
When I try to run an insert query from my Web site I get the following
error...
Error Diagnostic Information
ODBC Error Code = 22001 (String data right truncation)
[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data
would be truncated.
The error occurred while processing an element with a general
identifier of (CFQUERY), occupying document position (701:3) to
(701:73).
...but when I copy and paste the query into SQL Server Enterprise
Manager, the Insert succeeds.
Why does the query work in SQL Server Enterprise Manager but not from
my Web page? The Web page used to work fine.
My System Information:
====================== Windows 2000 Server (Operating System)
Cold Fusion 4.5 Server (Dynamic Web Server)
SQL Server 7.0 (Database Server)
The Query That Fails In The Web Page But Succeeds In Enterprise
Manager:
======================================================================== INSERT INTO dboJob(CUID, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
f13, f16, f17, f18, f19)
VALUES(
14036,
'09/17/2004 1:3:7 PM',
0,
'o',
'Testing new limit region functionality',
'Limit region should include cascading city, state or province,
country, and zip.',
'Fully functional.',
'',
'11',
'p',
'',
'',
'3',
'5',
0,
0 )
Table Information (field names have been changed to protect the
innocent):
========================================================================== CREATE TABLE [dbo].[dboJob] (
[JOID] [decimal](18, 0) IDENTITY (1, 1) NOT NULL ,
[CUID] [decimal](18, 0) NOT NULL ,
[f1] [varchar] (2) NOT NULL ,
[f2] [datetime] NOT NULL ,
[f3] [datetime] NOT NULL ,
[f4] [money] NOT NULL ,
[f5] [varchar] (1) NOT NULL ,
[f6] [varchar] (100) NULL ,
[f7] [varchar] (3000) NOT NULL ,
[f8] [varchar] (1500) NOT NULL ,
[f9] [varchar] (3000) NULL ,
[f10] [numeric](18, 0) NOT NULL ,
[f11] [char] (1) NOT NULL ,
[f12] [varchar] (200) NOT NULL ,
[f13] [varchar] (64) NULL ,
[f14] [varchar] (1) NOT NULL ,
[f15] [varchar] (1) NOT NULL ,
[f16] [varchar] (1) NOT NULL ,
[f17] [varchar] (1) NOT NULL ,
[f18] [money] NOT NULL ,
[f19] [money] NOT NULL ,
[f20] [datetime] NOT NULL
) ON [PRIMARY]
GO
Thanks,
NateI suggest you try the INSERT statement through QA. After the INSERT, check whether the data has been
truncated. Also, read about SET ANSI_WARNING.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"nate" <nathandeneau@.cox.net> wrote in message
news:4630acfb.0409141227.64eb7823@.posting.google.com...
> Hello Helpfull Helpers,
> When I try to run an insert query from my Web site I get the following
> error...
> Error Diagnostic Information
> ODBC Error Code = 22001 (String data right truncation)
> [Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data
> would be truncated.
> The error occurred while processing an element with a general
> identifier of (CFQUERY), occupying document position (701:3) to
> (701:73).
> ...but when I copy and paste the query into SQL Server Enterprise
> Manager, the Insert succeeds.
> Why does the query work in SQL Server Enterprise Manager but not from
> my Web page? The Web page used to work fine.
> My System Information:
> ======================> Windows 2000 Server (Operating System)
> Cold Fusion 4.5 Server (Dynamic Web Server)
> SQL Server 7.0 (Database Server)
> The Query That Fails In The Web Page But Succeeds In Enterprise
> Manager:
> ========================================================================> INSERT INTO dboJob(CUID, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
> f13, f16, f17, f18, f19)
> VALUES(
> 14036,
> '09/17/2004 1:3:7 PM',
> 0,
> 'o',
> 'Testing new limit region functionality',
> 'Limit region should include cascading city, state or province,
> country, and zip.',
> 'Fully functional.',
> '',
> '11',
> 'p',
> '',
> '',
> '3',
> '5',
> 0,
> 0 )
> Table Information (field names have been changed to protect the
> innocent):
> ==========================================================================> CREATE TABLE [dbo].[dboJob] (
> [JOID] [decimal](18, 0) IDENTITY (1, 1) NOT NULL ,
> [CUID] [decimal](18, 0) NOT NULL ,
> [f1] [varchar] (2) NOT NULL ,
> [f2] [datetime] NOT NULL ,
> [f3] [datetime] NOT NULL ,
> [f4] [money] NOT NULL ,
> [f5] [varchar] (1) NOT NULL ,
> [f6] [varchar] (100) NULL ,
> [f7] [varchar] (3000) NOT NULL ,
> [f8] [varchar] (1500) NOT NULL ,
> [f9] [varchar] (3000) NULL ,
> [f10] [numeric](18, 0) NOT NULL ,
> [f11] [char] (1) NOT NULL ,
> [f12] [varchar] (200) NOT NULL ,
> [f13] [varchar] (64) NULL ,
> [f14] [varchar] (1) NOT NULL ,
> [f15] [varchar] (1) NOT NULL ,
> [f16] [varchar] (1) NOT NULL ,
> [f17] [varchar] (1) NOT NULL ,
> [f18] [money] NOT NULL ,
> [f19] [money] NOT NULL ,
> [f20] [datetime] NOT NULL
> ) ON [PRIMARY]
> GO
> Thanks,
> Nate

Friday, February 24, 2012

Insert problem with single quotes

I have a problem with inserting a string with single quotes. For instance,

string testme = "we don't have anything";

insert into tableone (buff) values ("'" + testme + "'");

I get an error with the word "don't" with single quote. But if I delete the single quote "dont" then it inserts okay. Is is a bug in sql 2005? Please help. Thanks.

blumonde

blumonde:

I have a problem with inserting a string with single quotes. For instance,

string testme = "we don't have anything";

insert into tableone (buff) values ("'" + testme + "'");

I get an error with the word "don't" with single quote. But if I delete the single quote "dont" then it inserts okay. Is is a bug in sql 2005? Please help. Thanks.


No, it's not a bug with SQL Server 2005. To use that method, you would need to double up any single quotes within the testme string in order to "escape" them so that your INSERT statement works correctly.

However, you should be using parameters to pass UI-supplied values to your SQL statement. Here's the why:

Please, please, please, learn about injection attacks!

And here's the how:
How To: Protect From SQL Injection in ASP.NET
Using Parameterized Query in ASP.NET, Part 1
Using Parameterized Query in ASP.NET, Part 2
Using Parameterized Queries in ASP.Net
|||

tmorton:

blumonde:

I have a problem with inserting a string with single quotes. For instance,

string testme = "we don't have anything";

insert into tableone (buff) values ("'" + testme + "'");

I get an error with the word "don't" with single quote. But if I delete the single quote "dont" then it inserts okay. Is is a bug in sql 2005? Please help. Thanks.


No, it's not a bug with SQL Server 2005. To use that method, you would need to double up any single quotes within the testme string in order to "escape" them so that your INSERT statement works correctly.

However, you should be using parameters to pass UI-supplied values to your SQL statement. Here's the why:

Please, please, please, learn about injection attacks!

And here's the how:
How To: Protect From SQL Injection in ASP.NET
Using Parameterized Query in ASP.NET, Part 1
Using Parameterized Query in ASP.NET, Part 2
Using Parameterized Queries in ASP.Net

Thank you Tmorton. I think parameters will have solved the problem.

blumonde