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. Problem with auto increment.

Problem with auto increment.

Scheduled Pinned Locked Moved Visual Basic
helpdatabaselearning
4 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.
  • N Offline
    N Offline
    nazimghori
    wrote on last edited by
    #1

    hello every one I am having problem with increment, I want that regi_code declared below should be auto increment for that I I am using SQLServer 2005 as my back end. I wrote code as :- Dim newid As Integer = Val(obj.getvalsfrmtbl("select max(regi_code) from regi_mast")) + 1 Me.txt4.Text = newid Me.txt4.Enabled = False now the problem is it returns me value "1" this obj.getvalsfrmtbl is a function declared in class for getting one by one values from database eg:= Public Function getvalsfrmtbl(ByVal str) As String Try Dim res As String = "" If cn.State = ConnectionState.Open Then cn.Close() End If cn.Open() Dim cmd As New SqlCommand Dim dr As SqlDataReader dr = cmd.ExecuteReader If dr.HasRows = True Then dr.Read() res = dr.Item(0) Else res = "" End If dr.Close() cn.Close() Return res Catch ex As Exception Return 0 Finally cn.Close() End Try End Function if same thing i do with access as bac kend it worked but I need it to work with SQLServer 2005.. so, please help me.... I am beginner.... :) :)

    D R 2 Replies Last reply
    0
    • N nazimghori

      hello every one I am having problem with increment, I want that regi_code declared below should be auto increment for that I I am using SQLServer 2005 as my back end. I wrote code as :- Dim newid As Integer = Val(obj.getvalsfrmtbl("select max(regi_code) from regi_mast")) + 1 Me.txt4.Text = newid Me.txt4.Enabled = False now the problem is it returns me value "1" this obj.getvalsfrmtbl is a function declared in class for getting one by one values from database eg:= Public Function getvalsfrmtbl(ByVal str) As String Try Dim res As String = "" If cn.State = ConnectionState.Open Then cn.Close() End If cn.Open() Dim cmd As New SqlCommand Dim dr As SqlDataReader dr = cmd.ExecuteReader If dr.HasRows = True Then dr.Read() res = dr.Item(0) Else res = "" End If dr.Close() cn.Close() Return res Catch ex As Exception Return 0 Finally cn.Close() End Try End Function if same thing i do with access as bac kend it worked but I need it to work with SQLServer 2005.. so, please help me.... I am beginner.... :) :)

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      You have not set the CommandText for the SQLCommand object.

      Happy Holi[^] जय हिंद

      1 Reply Last reply
      0
      • N nazimghori

        hello every one I am having problem with increment, I want that regi_code declared below should be auto increment for that I I am using SQLServer 2005 as my back end. I wrote code as :- Dim newid As Integer = Val(obj.getvalsfrmtbl("select max(regi_code) from regi_mast")) + 1 Me.txt4.Text = newid Me.txt4.Enabled = False now the problem is it returns me value "1" this obj.getvalsfrmtbl is a function declared in class for getting one by one values from database eg:= Public Function getvalsfrmtbl(ByVal str) As String Try Dim res As String = "" If cn.State = ConnectionState.Open Then cn.Close() End If cn.Open() Dim cmd As New SqlCommand Dim dr As SqlDataReader dr = cmd.ExecuteReader If dr.HasRows = True Then dr.Read() res = dr.Item(0) Else res = "" End If dr.Close() cn.Close() Return res Catch ex As Exception Return 0 Finally cn.Close() End Try End Function if same thing i do with access as bac kend it worked but I need it to work with SQLServer 2005.. so, please help me.... I am beginner.... :) :)

        R Offline
        R Offline
        rajmca g
        wrote on last edited by
        #3

        Public Function getvalsfrmtbl() As Integer Try Dim res As Integer If cn.State = ConnectionState.Open Then cn.Close() End If cn.Open() Dim cmd As New SqlCommand("select max(regi_code) from regi_mast", cn) cmd.CommandType = CommandType.Text Dim dr As SqlDataReader Dim dr As SqlDataReader dr = cmd.ExecuteReader() If dr.HasRows = True Then dr.Read() res = CInt(dr.Item(0)) Else res = 0 End If dr.Close() cn.Close() Return res Catch ex As Exception Return 0 Finally cn.Close() End Try End Function just try this code in your class and in you front end coding write this code Dim newid As Integer = Val(obj.getvalsfrmtbl()) + 1 Me.txt4.Text = newid Me.txt4.Enabled = False

        N 1 Reply Last reply
        0
        • R rajmca g

          Public Function getvalsfrmtbl() As Integer Try Dim res As Integer If cn.State = ConnectionState.Open Then cn.Close() End If cn.Open() Dim cmd As New SqlCommand("select max(regi_code) from regi_mast", cn) cmd.CommandType = CommandType.Text Dim dr As SqlDataReader Dim dr As SqlDataReader dr = cmd.ExecuteReader() If dr.HasRows = True Then dr.Read() res = CInt(dr.Item(0)) Else res = 0 End If dr.Close() cn.Close() Return res Catch ex As Exception Return 0 Finally cn.Close() End Try End Function just try this code in your class and in you front end coding write this code Dim newid As Integer = Val(obj.getvalsfrmtbl()) + 1 Me.txt4.Text = newid Me.txt4.Enabled = False

          N Offline
          N Offline
          nazimghori
          wrote on last edited by
          #4

          thank u very much.. :-D :-D

          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