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. (VB.NET) How to execute Select Max("")

(VB.NET) How to execute Select Max("")

Scheduled Pinned Locked Moved Visual Basic
csharptutorial
6 Posts 4 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.
  • V Offline
    V Offline
    venkata lakshmi prasanna
    wrote on last edited by
    #1

    iam new to vb.net,iam posting the code i hav written please make modifications where ever neccesary cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as lastfrom EMP_DETAILS where EMP_PLACE='" & ComboBox1.Text & "'" cn.Open() While dr.Read cmd.ExecuteScalar() TextBox1.Text = dr.Item("last") End While cn.Close()

    H V C 3 Replies Last reply
    0
    • V venkata lakshmi prasanna

      iam new to vb.net,iam posting the code i hav written please make modifications where ever neccesary cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as lastfrom EMP_DETAILS where EMP_PLACE='" & ComboBox1.Text & "'" cn.Open() While dr.Read cmd.ExecuteScalar() TextBox1.Text = dr.Item("last") End While cn.Close()

      H Offline
      H Offline
      Harini N K
      wrote on last edited by
      #2

      Hi Check this example and apply your code .. You need not use while loop if you are executing ExecuteScalar as it returns one row only. Example from MSDN[^] Hope you got it..

      Harini

      1 Reply Last reply
      0
      • V venkata lakshmi prasanna

        iam new to vb.net,iam posting the code i hav written please make modifications where ever neccesary cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as lastfrom EMP_DETAILS where EMP_PLACE='" & ComboBox1.Text & "'" cn.Open() While dr.Read cmd.ExecuteScalar() TextBox1.Text = dr.Item("last") End While cn.Close()

        V Offline
        V Offline
        venkata lakshmi prasanna
        wrote on last edited by
        #3

        iam vb6.0 programmer,this code works fine in vb6.0,how to write same code in vb.net

        1 Reply Last reply
        0
        • V venkata lakshmi prasanna

          iam new to vb.net,iam posting the code i hav written please make modifications where ever neccesary cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as lastfrom EMP_DETAILS where EMP_PLACE='" & ComboBox1.Text & "'" cn.Open() While dr.Read cmd.ExecuteScalar() TextBox1.Text = dr.Item("last") End While cn.Close()

          C Offline
          C Offline
          Ch_Shahzad iqbal
          wrote on last edited by
          #4

          cn.Open() cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as last from EMP_DETAILS where PLACE='" & ComboBox1.Text & "'" dr=cmd.executeREADER While dr.Read TextBox1.Text = dr.Item("last") End While cn.Close() Now Check it

          V 1 Reply Last reply
          0
          • C Ch_Shahzad iqbal

            cn.Open() cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as last from EMP_DETAILS where PLACE='" & ComboBox1.Text & "'" dr=cmd.executeREADER While dr.Read TextBox1.Text = dr.Item("last") End While cn.Close() Now Check it

            V Offline
            V Offline
            venkata lakshmi prasanna
            wrote on last edited by
            #5

            hi iqbal ,it is displaying a message "The select statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect".

            A 1 Reply Last reply
            0
            • V venkata lakshmi prasanna

              hi iqbal ,it is displaying a message "The select statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect".

              A Offline
              A Offline
              advansis
              wrote on last edited by
              #6

              try this: cn.Open() cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as [last] from EMP_DETAILS where PLACE='" & ComboBox1.Text & "'" dr=cmd.executeREADER While dr.Read TextBox1.Text = dr.Item("last") End While cn.Close() Hope this helps you.

              Peace!

              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