Problem with auto increment.
-
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.... :) :)
-
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.... :) :)
-
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.... :) :)
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
-
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
thank u very much.. :-D :-D