Page 2 of 2 FirstFirst 12
Results 41 to 67 of 67

Thread: need an adivse

  1. #41
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: need an adivse

    Hey,

    You should use the Page.IsPostBack property:

    http://msdn.microsoft.com/en-us/libr...spostback.aspx

    To determine whether the page has actually been submitted or whether it has just been refreshed. Alternatively, once the user has clicked save, they are redirected to another page, just a thought.

    Gary

  2. #42
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    I'll second that - it's better to redirect them to a 'thank you' page.

  3. #43

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    ok , is there ayway to disbale the refresh button form the browser at this page andalso F5 , am with you that the redirect page is better , but jus asking ... if i can do it or not ,,

  4. #44
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: need an adivse

    hey,

    I am not aware of a way of doing this, but it is definitely not something that you want to base your logic on. Rather, use the re-direct as suggested by myself and mend, or use the IsPostBack method to decide what should be done.

    Gary

  5. #45
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    You can't disable F5 after the form has been submitted, but if you really want to stay on the same page, then you can (in the button click) process the details, redirect to the same page so that it's "fresh".

  6. #46

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    gep13 and mend thanks for your help , i was wondering if i can disable the F5 by any javascript in the code-behind page , but i'll take what you were suggested cuz i believe it's better as you said .. i'll come back soon

  7. #47
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    See you later.

  8. #48

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    still didnt get how i can wirte code to let user insert his survey's question and all questions will be under one SurveyID . i think i had confused abou how i can link the question table with the survey table & user table within the code
    Last edited by alqous; Apr 21st, 2009 at 06:31 PM.

  9. #49
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    Not sure what you mean, you did have the design in place, are you facing difficulties?

  10. #50

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    my difficulties is in code when i insert the question in question's table how i can let surveyID in survey's table increment ?

  11. #51
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    In the Questions table, the SurveyID is a foreign key. You need to insert that value along with the rest of the data in the Questions table.

  12. #52

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    you mean i have to insert the surveyid programmaticaly and if yes how i can associate many QID to one SurveyID .. i want a code hint

  13. #53
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: need an adivse

    Quote Originally Posted by alqous View Post
    .. i want a code hint
    I WANT a Ferrari, but that doesn't mean I am going to get one!!

    These forums are frequented by people who give up their time freely, so it would be nice if you could show some respect when asking for help!!

    Gary

  14. #54
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    You can do this based on your database design. Your database design, IIRC, allowed for one SurveyID to be linked to several QIDs. You need to make entries in that linked table. It's just an INSERT statement, try it out, show us where you get stuck.

  15. #55

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    thanx mend , i appreciate you help , i'll try with code and show it to you here , come back soon ...

  16. #56

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    kindly find below the insertb code :

    Code:
     Protected Sub btnsavesurvey_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsavesurvey.Click
            cs.conn.Open()
    
            Dim comm As New SqlCommand
            comm.CommandType = CommandType.StoredProcedure
            comm.CommandText = "SurveyIDTBLCONN"
    
    
            Try
    
                Select Case ddlquestionnaire.SelectedIndex
                    Case Is = 1
                        Dim cmd As New SqlCommand("insert into Questions(Question,SID,AnswerTypeID)values('" & txtq.Text & "','" & "@SurveyID" & "','" & 1 & "')", cs.conn)
    
    
                        cmd.ExecuteNonQuery()
    
    
                        MsgBox("تمت اضافة السؤال", MsgBoxStyle.Information, " احصائيات اون لاين")
    
                    Case Is = 2
    
                        Dim cmd As New SqlCommand("insert into Questions(Question,AnswerTypeID)values('" & txtq.Text & "','" & "@SurveyID" & "','" & 2 & "')", cs.conn)
    
    
                        cmd.ExecuteNonQuery()
    
    
                        MsgBox("تمت اضافة السؤال", MsgBoxStyle.Information, " احصائيات اون لاين")
    
                    Case Is = 3
                        Dim cmd As New SqlCommand("insert into Questions(Question,AnswerTypeID)values('" & txtq.Text & "','" & "@SurveyID" & "','" & 3 & "')", cs.conn)
    
    
                        cmd.ExecuteNonQuery()
    
    
                        MsgBox("تمت اضافة السؤال", MsgBoxStyle.Information, " احصائيات اون لاين")
    
                    Case Is = 4
    
                        Dim cmd As New SqlCommand("insert into Questions(Question,AnswerTypeID)values('" & txtq.Text & "','" & "@SurveyID" & "','" & 4 & "')", cs.conn)
    
    
                        cmd.ExecuteNonQuery()
    
    
                        MsgBox("تمت اضافة السؤال", MsgBoxStyle.Information, " احصائيات اون لاين")
    
    
                End Select
    
    
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            cs.conn.Close()
            cleartextboxz()
    
    
            Response.Redirect("addsurvey.aspx")
    
          
    
        End Sub
    and this is the stored procedure that i created :
    Code:
    ALTER PROCEDURE dbo.SurveyIDTBLCONN
    
    	
    AS
    	/* SET NOCOUNT ON */
    	Declare @SurveyID Int
    	Begin
    	
    	Set @SurveyID = Scope_Identity()
    	
    	Insert into Questions (SID) values (@SurveyID)
    	
    	End

    but still doesnt work , can't link the surveyID between the Question table and the survey table , could ypu plz help me ..

  17. #57
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    You have to link them in your database, not in code. What does your database look like right now?

  18. #58

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    kindly find the attached for the database.

    also in the question table the SuervyID (SID) it's foreginkey but not autoincrement .. QuestionID is autoincrement and identity

    in the suerveytable it's primarykey and identity autoincrement
    Attached Files Attached Files

  19. #59
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: need an adivse

    Hey alqous,

    Can I ask why you are using a case statement in the above code?

    You are using the exact same query in each case with the exception of the survey ID. Why not use a parameter in the query string, and the value of that parameter will be ddlquestionnaire.SelectedIndex.

    Related to that, you are concatentating the SQL string and building up the SQL string, this really should be avoided as it leaves you open to SQL Injection. To prevent this, you should always use parameterized queries. You can find an example of how to do this in this thread:

    http://www.vbforums.com/showthread.php?t=469872

    Hope that helps!!

    Gary

  20. #60
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    Right, so what you do is to create a new survey, insert a new row into Survey. SID, which should be autoincrement, should return a value to you, the new primary key. Use that to insert into Questions along with the new questions.

  21. #61

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    hey gep13

    Can I ask why you are using a case statement in the above code?
    am using case statment cuz i have different answertype everyone of it has there # , if you look at the end of each statment u'll find that all three are not the same ... but thanx for the hint and i'll try to do it by parameters to avoid Sql injection

    thanx agian

  22. #62

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    dear mend ,

    thank for helping me

    i'm little confused .. and i didnt get what you meant exactly .

    did you meant the SID in question should be autoincrement?

    I'm choosing the answertype from dropdown list and type the question then insert it in the database .. but at everytime i can insert one question then return back to insert the second one ..etc , after that i should generate a page that has the survey depend on what was insert

    am still confused about how to link the SID in Q table with SID in survey table , and also how i can let multiple qusetion has one SID ..

    should i use innerjoin?

  23. #63
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: need an adivse

    Quote Originally Posted by alqous View Post
    hey gep13



    am using case statment cuz i have different answertype everyone of it has there # , if you look at the end of each statment u'll find that all three are not the same ... but thanx for the hint and i'll try to do it by parameters to avoid Sql injection

    thanx agian
    Hey,

    But this is what I am talking about. Your answertype is exactly what the value of ddlquestionnaire.SelectedIndex is. i.e. within your case statement you do something like this:

    If ddlquestionnaire.SelectedIndex is 1, you put 1 in the SQL Query, if it is 2 you put a 2 in the query etc so in the same way as you add txtq.Text into the query, you can simply add ddlquestionnaire.SelectedIndex as well, the case statement is completely unnecessary.

    So your code would become:

    Code:
    Dim cmd As New SqlCommand("insert into Questions(Question,SID,AnswerTypeID)values(@QuestionText,@SurveyID, @AnswerTypeID)", cs.conn)
    Where
    @QuestionText is a parameter with a value of txtq.Text
    @SurveryID is a parameter with a value of (not sure where this comes from in your code)
    @AnswerTypeID is a parameter with a value of ddlquestionnaire.SelectedIndex

    Gary

  24. #64
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    First, do an INSERT into the Survey table. Then do a select on SCOPE_IDENTITY(), this will return to you the ID of the new survey row. (This has to be done in a stored procedure).

    Then, take that new Survey ID and everytime you INSERT into the questions table, include the SID as one of the values, which is this statement


    insert into Questions(Question,AnswerTypeID,SID)values('" & txtq.Text & "','" & "@SurveyID" & "','" & 2 & ",intSid')

    Is that making sense now?

  25. #65

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    the stored procedure :
    Code:
    	
    AS
    	 SET NOCOUNT ON
    	 
    	insert into SURVEY (UserID) values  ('1')
    	
    	Declare @SurveyID Int
    	Begin
    	
    	Set @SurveyID = Scope_Identity()
    	
    	Insert into Questions (SID) values (@SurveyID)
    	
    	End
    is it right ? i feel there is some thing wrong with it , am trying to figure out how to insert the userid in the surveytable withing the stored procedure.

  26. #66
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: need an adivse

    You can't insert into Questions if you don't have any questions. From this stored proc, you must return @SurveyId and hold on to that value in your code. When it's time to insert a new question, that's when you can use @SurveyId in the next stored procedure.

    Code:
    Declare @SurveyID Int
    insert into SURVEY (UserID) values  (@UserId)
    Set @SurveyID = Scope_Identity()
    SELECT @SurveyID

  27. #67

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    130

    Re: need an adivse

    ok , the stored procedure is now look like :


    Code:
    @UserId int
    	
    AS
    	
    	 SET NOCOUNT ON
    	 
    Declare @SurveyID Int
    
    insert into SURVEY (UserID) values  (@UserId)
    
    Set @SurveyID = Scope_Identity()
    
    SELECT @SurveyID

    and my code is became :

    Code:
    cs.conn.Open()
    
    
            Dim comm As New SqlCommand
            comm.CommandType = CommandType.StoredProcedure
            comm.CommandText = "SurveyIDTBLCONN"
    
            Try
                If (txtq.Text <> "" AndAlso ddlquestionnaire.SelectedIndex <> "0") Then
                    ' Insert Query using stored procedure
    
                    Dim cmd As New SqlCommand("insert into Questions(Question,SID,AnswerTypeID)values(@Question,@SurveyID,@AnswerTypeID)", cs.conn)
    
                    cmd.Parameters.AddWithValue("@Question", txtq.Text.Trim)
                    cmd.Parameters.AddWithValue("@AnswerTypeID", ddlquestionnaire.SelectedIndex)
                    cmd.Parameters.AddWithValue("@SurveyID", comm.ExecuteScalar)
                    cmd.ExecuteNonQuery()
              Else
        
                End If
    
    
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            cs.conn.Close()
            cleartextboxz()
    
    
            Response.Redirect("addsurvey.aspx")
    it's not working i dont now why ?

    and also could you tell me what is the way to let the survey belong to their users , so when the user login his CP page he can veiw his survey??

    thanx for everything ..

    TC
    Last edited by alqous; May 18th, 2009 at 02:47 PM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width