1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to update record

Discussion in 'C#' started by kharearch, Apr 25, 2008.

  1. #1
    I am writing following code to update record but it is not updating. Please help me to solve this problem.

    Dim objcommand As SqlCommand
    ' Dim objtextbox As TextBox
    Dim str As String = "update my set age = @age where name = @name"
    objcommand = New SqlCommand(str, objconnection)
    objcommand.Parameters.Add(New SqlParameter("@age", SqlDbType.Int, 4))
    objcommand.Parameters.Add(New SqlParameter("@name", SqlDbType.Char, 2))
    objcommand.Parameters("@age").Value = TextBox2.Text
    objcommand.Parameters("@name").Value = TextBox1.Text
    objcommand.Connection = objconnection
    objcommand.Connection.Open()
    objcommand.ExecuteNonQuery()
     
    kharearch, Apr 25, 2008 IP
  2. dgxshiny

    dgxshiny Greenhorn

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    23
    #2
    Parameters.Add is a depreciated function, I would switch to .AddWithValue


    Dim objcommand As SqlCommand
    ' Dim objtextbox As TextBox
    Dim str As String = "update my set age = @age where name = @name"
    objcommand = New SqlCommand(str, objconnection)
    objcommand.Parameters.AddWithValue("@age", TextBox2.Text)
    objcommand.Parameters.AddWithValue("@name", TextBox1.Text)
    objcommand.Connection = objconnection
    objcommand.Connection.Open()
    objcommand.ExecuteNonQuery()
    objcommand.Connection.Close()
     
    dgxshiny, Apr 25, 2008 IP