473,396 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Does Gridview UpdateCommand recognize IF?

My gridview update command seems to always execute the first part of the SQL
statement regardless of whether or not there is a value for the
@AutoNumberID parameter. Any ideas?

UpdateCommand="
IF @AutoNumberID IS NULL
INSERT INTO dbo.tblLanguageValues(LanguageCode, LookupID,
LanguageText)
VALUES (@LanguageCode, @LookupID, @LanguageText)
ELSE
UPDATE dbo.tblLanguageValues
SET LanguageText = @LanguageText
WHERE LanguageCode = @LanguageCode AND LookupID = @LookupID"
based on the SELECT stored procedure for the Gridview:
ALTER PROCEDURE [dbo].[uspGeneralLanguageMaintenanceValuesGet]
@LanguageCode varchar(20)
AS
IF @LanguageCode = 'EN-US'
SELECT
AutoNumberID, LanguageCode,
LookupID, LanguageText, LanguageText as English, ToDo
FROM
dbo.tblLanguageValues
WHERE
LanguageCode = 'EN-US'
ELSE
SELECT
LV.AutoNumberID, @LanguageCode AS LanguageCode,
US.LookupID, LV.LanguageText, US.LanguageText as English,
LV.ToDo
FROM
dbo.tblLanguageValues US
LEFT OUTER JOIN dbo.tblLanguageValues LV
ON US.LookupID = LV.LookupID AND
LV.LanguageCode = @LanguageCode
WHERE
US.LanguageCode = 'EN-US'
Aug 26 '08 #1
2 1207
Mark
Where do you assign a value to @AutoNumberID variable?

"Mark B" <no*****@none.comwrote in message
news:e8**************@TK2MSFTNGP04.phx.gbl...
My gridview update command seems to always execute the first part of the
SQL statement regardless of whether or not there is a value for the
@AutoNumberID parameter. Any ideas?

UpdateCommand="
IF @AutoNumberID IS NULL
INSERT INTO dbo.tblLanguageValues(LanguageCode, LookupID,
LanguageText)
VALUES (@LanguageCode, @LookupID, @LanguageText)
ELSE
UPDATE dbo.tblLanguageValues
SET LanguageText = @LanguageText
WHERE LanguageCode = @LanguageCode AND LookupID = @LookupID"
based on the SELECT stored procedure for the Gridview:
ALTER PROCEDURE [dbo].[uspGeneralLanguageMaintenanceValuesGet]
@LanguageCode varchar(20)
AS
IF @LanguageCode = 'EN-US'
SELECT
AutoNumberID, LanguageCode,
LookupID, LanguageText, LanguageText as English, ToDo
FROM
dbo.tblLanguageValues
WHERE
LanguageCode = 'EN-US'
ELSE
SELECT
LV.AutoNumberID, @LanguageCode AS LanguageCode,
US.LookupID, LV.LanguageText, US.LanguageText as English,
LV.ToDo
FROM
dbo.tblLanguageValues US
LEFT OUTER JOIN dbo.tblLanguageValues LV
ON US.LookupID = LV.LookupID AND
LV.LanguageCode = @LanguageCode
WHERE
US.LanguageCode = 'EN-US'


Aug 26 '08 #2

It's part of the SELECT statement for the Gridview in the stored procedure
(uspGeneralLanguageMaintenanceValuesGet) I listed at the end of this post.
From what I understand ASP.NET looks for a field in SqlDataSource3 that has
exactly the same name as the parameter (less the @ character), even if no
column uses that field name in the Gridview. In my case I added a column
titled "#" with it's datavalue set to AutoNumberID just in case it needed
it.

The Autonumber field by the way is an identity field in the SQL database:
[AutoNumberID] [int] IDENTITY(1,1) NOT NULL
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
DeleteCommand="DELETE FROM [tblLanguageValues] WHERE [LanguageCode] =
@LanguageCode AND [LookupID] = @LookupID"
InsertCommand="INSERT INTO [tblLanguageValues] ([LanguageText],
[LanguageCode], [LookupID]) VALUES (@LanguageText, @LanguageCode,
@LookupID)"
SelectCommand="uspGeneralLanguageMaintenanceValues Get"
SelectCommandType="StoredProcedure"
UpdateCommand="
IF @AutoNumberID IS NULL
INSERT INTO dbo.tblLanguageValues(LanguageCode, LookupID,
LanguageText)
VALUES (@LanguageCode, @LookupID, @LanguageText)
ELSE
UPDATE dbo.tblLanguageValues
SET LanguageText = @LanguageText
WHERE LanguageCode = @LanguageCode AND LookupID = @LookupID">

<UpdateParameters>
<asp:Parameter Name="AutoNumberID" Type="Int32" />
<asp:Parameter Name="LanguageText" Type="String" />
<asp:Parameter Name="LanguageCode" Type="String"/>
<asp:Parameter Name="LookupID" Type="Int32"/>
</UpdateParameters>

<SelectParameters>
<asp:Parameter Name="LanguageCode" Type="String" />
</SelectParameters>

<DeleteParameters>
<asp:Parameter Name="LanguageCode" Type="String" />
<asp:Parameter Name="LookupID" Type="Int32" />
</DeleteParameters>

<InsertParameters>
<asp:Parameter Name="LanguageText" Type="String" />
<asp:Parameter Name="LanguageCode" Type="String" />
<asp:Parameter Name="LookupID" Type="Int32" />
</InsertParameters>
</asp:C>


"Uri Dimant" <ur**@iscar.co.ilwrote in message
news:OT**************@TK2MSFTNGP03.phx.gbl...
Mark
Where do you assign a value to @AutoNumberID variable?

"Mark B" <no*****@none.comwrote in message
news:e8**************@TK2MSFTNGP04.phx.gbl...
>My gridview update command seems to always execute the first part of the
SQL statement regardless of whether or not there is a value for the
@AutoNumberID parameter. Any ideas?

UpdateCommand="
IF @AutoNumberID IS NULL
INSERT INTO dbo.tblLanguageValues(LanguageCode, LookupID,
LanguageText)
VALUES (@LanguageCode, @LookupID, @LanguageText)
ELSE
UPDATE dbo.tblLanguageValues
SET LanguageText = @LanguageText
WHERE LanguageCode = @LanguageCode AND LookupID = @LookupID"
based on the SELECT stored procedure for the Gridview:
ALTER PROCEDURE [dbo].[uspGeneralLanguageMaintenanceValuesGet]
@LanguageCode varchar(20)
AS
IF @LanguageCode = 'EN-US'
SELECT
AutoNumberID, LanguageCode,
LookupID, LanguageText, LanguageText as English, ToDo
FROM
dbo.tblLanguageValues
WHERE
LanguageCode = 'EN-US'
ELSE
SELECT
LV.AutoNumberID, @LanguageCode AS LanguageCode,
US.LookupID, LV.LanguageText, US.LanguageText as English,
LV.ToDo
FROM
dbo.tblLanguageValues US
LEFT OUTER JOIN dbo.tblLanguageValues LV
ON US.LookupID = LV.LookupID AND
LV.LanguageCode = @LanguageCode
WHERE
US.LanguageCode = 'EN-US'


Aug 26 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: msnews.microsoft.com | last post by:
I've got a paging and sorting enabled GridView whose datasource is and AccessDataSource. I build the SelectCommand at PageLoad - it's a union query to show items and comments of the user logged...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
1
by: Avanti | last post by:
Hello, I have a gridview wherein I've added functionality for Edit. Now, when I click on the Edit button, and modify a field, and click on the Update button, the new values disappear and the old...
3
by: Dabbler | last post by:
I have a checkbox control in a GridView EditItemTemplate. My SqlDataAdapter complains when I try and use UpdateCommand Thanks on any binding clarification. GridView: <asp:TemplateField...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
0
by: troyblakely | last post by:
I have a gridview which is pulling data from a SqlDataSource, the select command queries a view and the update command is a stored procedure. I'm using a stored procedure because several tables...
2
by: foocc | last post by:
Hi. I have a problem with gridview whereby when i want to update 1 row, other row changes as well. For example, i change the quantity in row 1 from 1 to 2, but when i click on update, other row's...
0
by: BizWeb | last post by:
Hi, i am new to ASP.NET. I have write a very simple code to try the updating of the GridView but it is not updating the data. Below is the simple code that i have use. <%@ Page Language="vb"...
2
by: xMetalDetectorx | last post by:
Hi Everyone, I have a very simple web app that uses .Net 2.0 login control to authenticate users and allow access to an "admin" folder. Inside that admin folder I have one page that has a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.