Web Analytics Made Easy -
StatCounter SQL Statement...Urgent!!! - CodingForum

Announcement

Collapse
No announcement yet.

SQL Statement...Urgent!!!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL Statement...Urgent!!!

    hi,i'm newbie in mysql....can somebody help me????!!!!!

    for sql statement....when i used SELECT MAX then +1....means i want to select the max value form database and automatically generate a value +1....

    but the problem is...when i delete the record from database....the generated value will show for eg. 7,then i submit again....but inside the database will show for eg. 18....y??

    thank you very much!!

  • #2
    You can read up on the Posting guidelines here.

    Can you provide the query you use?

    Comment


    • #3
      here is my code:

      strSql = "select max (OrderID) as MaxOrderID from Orders"
      Dim myConnection As New SqlConnection("workstation id=R2_STUD12;packet size=4096;integrated security=SSPI;initial catalog=Orders;persist security info=False")

      myConnection.Open()

      command = New SqlCommand(strSql, myConnection)
      Try
      Dim reader As SqlDataReader = command.ExecuteReader
      While reader.Read

      TextBox1.Text = reader.Item("MaxOrderID") + 1

      End While
      'reader.Close()
      Catch ex As Exception
      Response.Write(ex.Message)
      End Try
      thanks for helping

      Comment


      • #4
        Who else is using this database at the same time as you?

        Comment


        • #5
          Is there any compelling reason you are not taking advantage of the "auto-increment" features on that ID field?

          Comment


          • #6
            Use an auto increment field and don't rely on max(fieldname) to change data in a different field or table. This article on using last_insert_id along with auto increment should explain things.

            Comment


            • #7
              okok....

              finally i knew the answer already....is IDENT_CURRENT

              thanks for helping....

              Comment

              Working...
              X