Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. sample update query in vb.net

sample update query in vb.net

Scheduled Pinned Locked Moved Visual Basic
databasehelpcsharpsql-server
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JustmeNick
    wrote on last edited by
    #1

    can anyone help me to write a sample update query to update some text and interger fields in my database..i am using sql server 2000... please send me a sample one that works.. so i can test it and modify it to use in my project...thanks.. having problem writing mine..

    Nab

    M 1 Reply Last reply
    0
    • J JustmeNick

      can anyone help me to write a sample update query to update some text and interger fields in my database..i am using sql server 2000... please send me a sample one that works.. so i can test it and modify it to use in my project...thanks.. having problem writing mine..

      Nab

      M Offline
      M Offline
      Marcus J Smith
      wrote on last edited by
      #2

      Why dont you post what you have so far and we can point you in the correct direction.


      CleAkO

      "I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy
      "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)

      J 1 Reply Last reply
      0
      • M Marcus J Smith

        Why dont you post what you have so far and we can point you in the correct direction.


        CleAkO

        "I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy
        "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)

        J Offline
        J Offline
        JustmeNick
        wrote on last edited by
        #3

        its generated by webmatrix.. but its just not updating a field that is already in the table which has a string value...don't know why.. Dim queryString As String = "UPDATE [R_Application] SET [Fname]=@Fname, [Mname]=@Mname, [Lname]=@Lname WHERE (" & _ "[R_Application].[AppId] = @AppId)" if the field was null then it works..but if some value exist..it doesn't update...

        Nab

        M G 2 Replies Last reply
        0
        • J JustmeNick

          its generated by webmatrix.. but its just not updating a field that is already in the table which has a string value...don't know why.. Dim queryString As String = "UPDATE [R_Application] SET [Fname]=@Fname, [Mname]=@Mname, [Lname]=@Lname WHERE (" & _ "[R_Application].[AppId] = @AppId)" if the field was null then it works..but if some value exist..it doesn't update...

          Nab

          M Offline
          M Offline
          Marcus J Smith
          wrote on last edited by
          #4

          Is this the same query it always uses?


          CleAkO

          "I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy
          "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)

          J 1 Reply Last reply
          0
          • J JustmeNick

            its generated by webmatrix.. but its just not updating a field that is already in the table which has a string value...don't know why.. Dim queryString As String = "UPDATE [R_Application] SET [Fname]=@Fname, [Mname]=@Mname, [Lname]=@Lname WHERE (" & _ "[R_Application].[AppId] = @AppId)" if the field was null then it works..but if some value exist..it doesn't update...

            Nab

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            You have to show more of your code. What you describe doesn't make sense if one only looks at the SQL query. An update query doesn't care if the value in the field is null or not, it updates the field in either case.

            --- single minded; short sighted; long gone;

            J 1 Reply Last reply
            0
            • M Marcus J Smith

              Is this the same query it always uses?


              CleAkO

              "I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy
              "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)

              J Offline
              J Offline
              JustmeNick
              wrote on last edited by
              #6

              yes same query..what wrong with it?... just do one and send it to me..let me try it

              Nab

              1 Reply Last reply
              0
              • G Guffa

                You have to show more of your code. What you describe doesn't make sense if one only looks at the SQL query. An update query doesn't care if the value in the field is null or not, it updates the field in either case.

                --- single minded; short sighted; long gone;

                J Offline
                J Offline
                JustmeNick
                wrote on last edited by
                #7

                Ok..this is the exact query i am using.... Function testUpdate(ByVal appId As Integer, ByVal fname As String, ByVal lname As String) As Integer Dim connectionString As String = "server='(local)'; trusted_connection=true; database='TESTDBfhms'" Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString) Dim queryString As String = "UPDATE [R_Application] SET [Fname]=@Fname, [Lname]=@Lname WHERE ([R_Application]."& _ "[AppId] = @AppId)" Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim dbParam_appId As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_appId.ParameterName = "@AppId" dbParam_appId.Value = appId dbParam_appId.DbType = System.Data.DbType.Int32 dbCommand.Parameters.Add(dbParam_appId) Dim dbParam_fname As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_fname.ParameterName = "@Fname" dbParam_fname.Value = fname dbParam_fname.DbType = System.Data.DbType.[String] dbCommand.Parameters.Add(dbParam_fname) Dim dbParam_lname As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_lname.ParameterName = "@Lname" dbParam_lname.Value = lname dbParam_lname.DbType = System.Data.DbType.[String] dbCommand.Parameters.Add(dbParam_lname) Dim rowsAffected As Integer = 0 dbConnection.Open Try rowsAffected = dbCommand.ExecuteNonQuery Finally dbConnection.Close End Try Return rowsAffected End Function

                Nab

                G 1 Reply Last reply
                0
                • J JustmeNick

                  Ok..this is the exact query i am using.... Function testUpdate(ByVal appId As Integer, ByVal fname As String, ByVal lname As String) As Integer Dim connectionString As String = "server='(local)'; trusted_connection=true; database='TESTDBfhms'" Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString) Dim queryString As String = "UPDATE [R_Application] SET [Fname]=@Fname, [Lname]=@Lname WHERE ([R_Application]."& _ "[AppId] = @AppId)" Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim dbParam_appId As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_appId.ParameterName = "@AppId" dbParam_appId.Value = appId dbParam_appId.DbType = System.Data.DbType.Int32 dbCommand.Parameters.Add(dbParam_appId) Dim dbParam_fname As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_fname.ParameterName = "@Fname" dbParam_fname.Value = fname dbParam_fname.DbType = System.Data.DbType.[String] dbCommand.Parameters.Add(dbParam_fname) Dim dbParam_lname As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_lname.ParameterName = "@Lname" dbParam_lname.Value = lname dbParam_lname.DbType = System.Data.DbType.[String] dbCommand.Parameters.Add(dbParam_lname) Dim rowsAffected As Integer = 0 dbConnection.Open Try rowsAffected = dbCommand.ExecuteNonQuery Finally dbConnection.Close End Try Return rowsAffected End Function

                  Nab

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  There is nothing wrong with that code. Debug the code and watch where you get the values from, as I suggested in the other thread.

                  --- single minded; short sighted; long gone;

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups