Welcome to Dream.In.Code
Become an Expert!

Join 149,929 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,787 people online right now. Registration is fast and FREE... Join Now!




Forward to new page if INSERT successful

 
Reply to this topicStart new topic

Forward to new page if INSERT successful

Rating  5
pabs1983
21 Jan, 2008 - 04:53 AM
Post #1

New D.I.C Head
*

Joined: 14 Dec, 2006
Posts: 30



Thanked: 1 times
My Contributions
Hi guys,

I am sure this is dead easy, but i cant find anything on this at the moment.

I currently have a datasource and a detailsview. I have a INSERT SQL query that puts data into the database. This all works. What i want to know, is how to make this page forward to a different page if it works, and display a message if it fails.

I haven't posted any code, as there isn't any problems (at current with it).

Any advice would be gratefully recieved.

Many Thanks
Pabs
User is offlineProfile CardPM
+Quote Post

girasquid
RE: Forward To New Page If INSERT Successful
21 Jan, 2008 - 07:04 PM
Post #2

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,295



Thanked: 18 times
Dream Kudos: 725
My Contributions
I don't think there's a way to actually have your INSERT statement definitively return a value.

However, what you could do is a quick SELECT based on the data you entered, assuming that it's at least mildly unique - so you'd first INSERT the new row, and then you'd run a SELECT query using the data you inserted(maybe a COUNT() statement or something), to make sure that the data is there.
User is online!Profile CardPM
+Quote Post

pabs1983
RE: Forward To New Page If INSERT Successful
1 Feb, 2008 - 04:51 AM
Post #3

New D.I.C Head
*

Joined: 14 Dec, 2006
Posts: 30



Thanked: 1 times
My Contributions
i think i found it. On the datasource there is a OnInserted action, you can then add a redirect in the code behind.

biggrin.gif

not proved it yet tho as i am away from my own computer.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Forward To New Page If INSERT Successful
1 Feb, 2008 - 07:10 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Actually, if you're doing it all in code (no drag n drop controls) there is a way to have your INSERT statement return a value, and from that value tell if it was successful. When using ExecuteNonQuery it will return the number of rows affected, if it returns a zero (0) you know your statement failed, something along the lines of:


CODE

Dim status As Integer

....all your insert and database code

'Now get the return value
status = YourCommandObject.ExecuteNonQuery()

'now check the value
If Not status = 0 then
    System.Web.HttpContext.Current.Response.Redirect("YourPage.aspx")
Else
    System.Web.HttpContext.Current.Response.Write("Your Error Message Here")
End If



Hope that helps some smile.gif
User is offlineProfile CardPM
+Quote Post

dilipv
RE: Forward To New Page If INSERT Successful
9 Feb, 2008 - 04:19 AM
Post #5

New D.I.C Head
*

Joined: 9 Feb, 2008
Posts: 9

hi there,


With the help of If condition, if the condition is true then Response.Redirect("http://www.your website.com")

hope this will sole your query.

Thank you
Jitesh
.Net Consulting
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 03:17PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month