Click here to Skip to main content
15,887,338 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionResizing Windows Forms Pin
briogene10-Mar-09 0:24
briogene10-Mar-09 0:24 
AnswerRe: Resizing Windows Forms Pin
Dave Kreskowiak10-Mar-09 7:48
mveDave Kreskowiak10-Mar-09 7:48 
Questionmerge module for crystal report [modified] Pin
hrishiS10-Mar-09 0:21
hrishiS10-Mar-09 0:21 
QuestionSetup in vb.net Pin
mahalakshmi4210-Mar-09 0:17
mahalakshmi4210-Mar-09 0:17 
AnswerRe: Setup in vb.net Pin
briogene10-Mar-09 0:28
briogene10-Mar-09 0:28 
QuestionUser Control Sub Properties. Pin
Nanda_MR9-Mar-09 23:39
Nanda_MR9-Mar-09 23:39 
AnswerRe: User Control Sub Properties. Pin
Dave Kreskowiak10-Mar-09 7:40
mveDave Kreskowiak10-Mar-09 7:40 
QuestionIncrement using Database Pin
nazimghori9-Mar-09 23:31
nazimghori9-Mar-09 23:31 
hello every one

i want to generate one of the field of database as auto increment in my project for that i wrote code as:- 'database is in Sqlserver 2005'

Dim newid As Integer=Val(obj.getvalsfrmtbl("select max regi_code from regi_mast")) +1

Me.txt4.Text = newid
Me.txt4.Enabled = False

where obj.getvalsfrmtbl is a function in class for getting one by one values from database... like

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


to this i got solution like

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

Dim newid As Integer = Val(obj.getvalsfrmtbl()) + 1
Me.txt4.Text = newid
Me.txt4.Enabled = False


but this is not true for database having more then one table ..

so what shall i do

please help..... Smile | :) Smile | :) Smile | :)
GeneralRe: Increment using Database Pin
Luc Pattyn10-Mar-09 0:58
sitebuilderLuc Pattyn10-Mar-09 0:58 
AnswerRe: Increment using Database Pin
Jon_Boy10-Mar-09 2:19
Jon_Boy10-Mar-09 2:19 
QuestionSchool Calendar using VB.Net Pin
wr30289-Mar-09 21:01
wr30289-Mar-09 21:01 
AnswerRe: School Calendar using VB.Net Pin
0x3c09-Mar-09 21:13
0x3c09-Mar-09 21:13 
GeneralRe: School Calendar using VB.Net Pin
wr302810-Mar-09 1:38
wr302810-Mar-09 1:38 
GeneralRe: School Calendar using VB.Net Pin
EliottA10-Mar-09 3:38
EliottA10-Mar-09 3:38 
GeneralRe: School Calendar using VB.Net Pin
wr302810-Mar-09 6:58
wr302810-Mar-09 6:58 
GeneralRe: School Calendar using VB.Net Pin
0x3c010-Mar-09 7:04
0x3c010-Mar-09 7:04 
GeneralRe: School Calendar using VB.Net Pin
wr302810-Mar-09 18:31
wr302810-Mar-09 18:31 
GeneralRe: School Calendar using VB.Net Pin
wr302810-Mar-09 18:54
wr302810-Mar-09 18:54 
QuestionHighlight the background color Pin
BalasubramanianK9-Mar-09 20:02
BalasubramanianK9-Mar-09 20:02 
AnswerRe: Highlight the background color Pin
0x3c09-Mar-09 21:10
0x3c09-Mar-09 21:10 
GeneralRe: Highlight the background color Pin
BalasubramanianK9-Mar-09 23:30
BalasubramanianK9-Mar-09 23:30 
Questionabout web.config Pin
rajmca.g9-Mar-09 19:42
rajmca.g9-Mar-09 19:42 
QuestionProblem with auto increment. Pin
nazimghori9-Mar-09 18:11
nazimghori9-Mar-09 18:11 
AnswerRe: Problem with auto increment. Pin
dan!sh 9-Mar-09 18:17
professional dan!sh 9-Mar-09 18:17 
AnswerRe: Problem with auto increment. Pin
rajmca.g9-Mar-09 19:57
rajmca.g9-Mar-09 19:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.