Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 11th, 2007, 06:48 PM
Registered User
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default GridView and SqlDataSource Woes

I'm new to ASP NET 2.0 and Visual Studio 2005. I'm setting up a page that pulls data from a SQL database. I'm using a custom SQL query in the data source because I want to perform some actions on the data before it is displayed in the gridview. I guess because of this I have to also supply my own Edit and Delete statements instead of selecting their nice check box in the advanced area. The problem I'm running in to is that when I run my page and click on the edit or delete links it acts like every thing is fine, but the data hasn't changed. Neither on the web page or in the db table itself. I don't know this for sure, but it seems like my T-SQL statement is solid except for the WHERE clause. I'm concerened that it isn't updating / deleting because I'm not referencing the row to be updated properly. Also, the data in the table doesn't have any single row that is unique so my primary key is actually two rows combined. Below are the SELECT, UPDATE, and DELETE statements I'm trying to use.

SELECT Statement (This works just fine, but here for reference)
SELECT [JobName], [CompState], [BackupType], [StartTime], DATEDIFF(n,'12/30/1899 00:00:00',[Queue]) AS Queue, DATEDIFF(n,'12/30/1899 00:00:00',[Duration]) AS Duration, [DataWritten], [CentComplete], [SessionID], [Error], [ReportCreator], [NumMedia], [NumErrors], [NumWar], [NumFiles], [ReportDate] FROM [tblReportData] WHERE MONTH([ReportDate]) = MONTH(GETDATE()) AND DAY([ReportDate]) = DAY(GETDATE()) AND YEAR([ReportDate]) = YEAR(GETDATE())

UPDATE Statement
UPDATE tblReportData SET JobName = @JobName, CompState = @CompState, BackupType = @BackupType, StartTime = @StartTime, Queue = @Queue, Duration = @Duration, DataWritten = @DataWritten, NumMedia = @NumMedia, NumErrors = @NumErrors, NumWar = @NumWar, NumFiles = @NumFiles, CentComplete = @CentComplete, SessionID = @SessionID, Error = @Error, ReportCreator = @ReportCreator, ReportDate = @ReportDate WHERE (JobName = @original_JobName) AND (ReportDate = MONTH(@original_ReportDate)) AND (ReportDate = DAY(@original_ReportDate)) AND (ReportDate = YEAR(@original_ReportDate))

DELETE Statement
DELETE FROM [tblReportData] WHERE [JobName] = @original_JobName AND MONTH([ReportDate]) = MONTH(@original_ReportDate) AND DAY([ReportDate]) = DAY(@original_ReportDate) AND YEAR([ReportDate]) = YEAR(@original_ReportDate)

Mike Jones

Old January 16th, 2007, 02:11 PM
rlb rlb is offline
Authorized User
Join Date: Jan 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts

I had this problem as well.
Try this:

    void Page_Load(Object sender, EventArgs e)
        //give gridview our sql query if page is postback
        if (Page.IsPostBack && Session["lastQuery"] != null)
            getResultsSource.SelectCommand = myStringQuery;

It might also help if your sql string query was a session variable.

Similar Threads
Thread Thread Starter Forum Replies Last Post
conn from Gridview to SqldataSource veda Visual Studio 2005 2 July 9th, 2008 11:49 PM
Fill gridview from 2 tables using sqldatasource niktos ASP.NET 2.0 Basics 1 January 30th, 2007 10:45 AM
Gridview/SqlDataSource won't show results fizzerchris ASP.NET 2.0 Professional 4 September 27th, 2006 02:35 PM
Form woes komputatek Access 2 March 15th, 2005 11:47 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.