Results 1 to 5 of 5

Thread: Update query not working properly in asp.net

  1. #1
    Join Date
    Nov 2009
    Posts
    57

    Update query not working properly in asp.net

    Hello to all,
    I am new to this forum. I am developing a website for one company. I get problem in updating query. When I use that code in query analyzer it works fine, but nothing happens using the webpage. I don't know why my code doesn't update properly. I don't know why update query not working properly in asp.net. Can anyone tell me. Please help me.
    Thanks in advanced.
    Last edited by Linoo; 19-01-2010 at 09:06 PM.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Update query not working properly in asp.net

    Hey you are getting this problem due to missing command " myCmd.ExecuteNonQuery();" You can include this command as follows.


    Code:
    Dim ConStr1 As String = ConfigurationManager.ConnectionStrings("SqlDataS1").ConnectionString<br>    
    Dim myConn1 As New SqlConnection(ConStr1)<br>   <br>    
    'open connection'<br>      myConn1.Open()<br>    <br>                    <br>                         
    Dim q As String = "UPDATE pages SET pagetitle ='" & Trim(title.text) & "', pagesummary= '" & Trim(summary.value) & "' , pagebody='" & Trim(body.value) & "' WHERE pageid =" & qvalue<br>                   
    Dim myCmd As SqlCommand = New SqlCommand(q, myConn1)
    myConn1.Close()

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Update query not working properly in asp.net

    You have to use following code to for update query. It is one of the most simple and basic code to update query in Asp.net.
    Code:
    private Boolean InsertUpdateData(SqlCommand cmd)
    {
    
        String strCS = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
    
        SqlConnection c1 = new SqlConnection(strCS);
    
        cmd.CommandType = CommandType.Text;
    
        cmd.Connection = c1;
    
        try
    
        {
    
            c1.Open();
    
            cmd.ExecuteNonQuery();
    
            return true;
    
        }
    
        catch (Exception ex)
    
        {
    
            Response.Write(ex.M1);
    
            return false;
    
        }
    
        finally
    
        {
    
            c1.Close();
    
            c1.Dispose();
    
        }
    
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Update query not working properly in asp.net

    I also had the same problem then I able to fix this problem by using following code. I think you also use this code to get rid out of this problem. Just don't vopy paste following code in your project, try to understand that.



    Code:
    
    
    While (reader.Read())
           {        
    mydata &="<vid id='leftsite'><b2>" & reader.Item("title") & "</b2>" & reader.Item("summary") & reader.Item("pagebody") & "</vid>"
    
    if pagesub != 0
    
    // display subpages here
    
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Update query not working properly in asp.net

    Have you try following type of code in your query? If not, then try to use following code in your project. This code is used to update and insert query in asp.net.

    Code:
    if reader.Read()
        mydata &= reader.Item("title") & "</ br>"
            if reader.Item("subpage") = reader.Item("idpage")
                SD = "<div class='menusub'>"
                    While reader.Item("subpage") = reader.Item("idpage")
                    SD &= reader.Item("title") & "<br />"
                    End While
                SD &= "</div>"
            end if
    End If

Similar Threads

  1. Replies: 5
    Last Post: 21-04-2012, 10:19 PM
  2. nokia c6-00 not working properly after firmware update
    By Eswarapu in forum Portable Devices
    Replies: 6
    Last Post: 16-07-2011, 11:13 PM
  3. Replies: 5
    Last Post: 08-05-2011, 05:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,225,216.96828 seconds with 17 queries