PDA

View Full Version : Unable to insert into database with parameters instead of strings (MyLittleAdmin)


freakonaleashlp
04-08-2009, 03:58 AM
Hi,

I am trying to insert data into the 'orderdata' table using an SqlDataSource's InsertCommand. However, when I checked the Insert Query Generator on the control panel of MLA, I found that the generated query contains an "N" character before every text entry. What is the significance of this?


Also, when the InsertCommand is set to string values, like so:


USE [SQL2005_576508_k2sd] INSERT INTO [dbo].[orderdata] ([Name], [Address], [State], [ZipCode], [Country], [Email], [PhoneNo], [CellPhoneMake], [CellPhoneModel], [CellPhoneOSRev], [CarMake], [CarModel], [CarYear], [CarMake2], [CarModel2], [CarYear2], [Service], [Type]) VALUES (N'Yohan ', N'Blah ', N'UT', 84102, N'USA ', N'rsfsc ', 9898, N'Apple ', N'iPhone ', N'3.2 ', N'Audi ', N'A4 ', 2009, N'Audi ', N'S4 ', 2009, 1, 2


it works, but if it is set to form parameters defined in the code, like so:


USE [SQL2005_576508_k2sd] INSERT INTO [dbo].[orderdata] ([Name], [Address], [State], [ZipCode], [Country], [Email], [PhoneNo], [CellPhoneMake], [CellPhoneModel], [CellPhoneOSRev], [CarMake], [CarModel], [CarYear], [CarMake2], [CarModel2], [CarYear2], [Service], [Type]) VALUES (N @Name, N @Address, N @State, @ZipCode, N @Country, N @Email, @PhoneNo, N @CellPhoneMake, N @CellPhoneModel, N @CellPhoneOSRev, N @CarMake, N @CarModel, @CarYear, N @CarMake2, N @CarModel2, @CarYear2, @Service, @Type)


it does not work, with or without the "N", with or without a space between the "N" and the @variable.


Please help!


Thanks,
Rohan

wisemx
04-08-2009, 05:55 AM
Hi,
The N is an expression, handy but you do have to be careful.
From SQL Server Books-on-line:

When referencing the Unicode character data types nchar, nvarchar, and ntext, 'expression' should be prefixed with the capital letter 'N'. If 'N' is not specified, SQL Server converts the string to the code page that corresponds to the default collation of the database or column. Any characters not found in this code page are lost.
http://msdn.microsoft.com/en-us/library/ms174335.aspx

Get a handle on that then post again if you need help.
Salute,
Mark

freakonaleashlp
04-08-2009, 10:11 AM
Thanks, Mark. My data fields are of the type 'varchar'. Is there any way I can use the formparameters (the variables preceded by the '@' symbol) and get them to work with the InsertCommand?

Thanks,
Rohan

freakonaleashlp
04-08-2009, 03:09 PM
Looks like I answered my own question!

:)
Rohan

wisemx
04-08-2009, 03:56 PM
Cool ;-)

Gotta run, my 4 year old just called his 9 year old brother a "big fat booty"

If you need any more help feel free to post, I'll be downstairs taking about respect and honor. :-)
Salute,
Mark