Saturday, April 4, 2009

Auto generate a number in VB

Dim query As String
Dim query1 As String
Dim i As Integer
Dim obj_data_access As New data_access
Dim dt As DataTable
Dim ds As New System.Data.DataSet
Dim rowcount As Integer
Dim dv As DataView
Dim dp1 As String
Dim dp2 As String
dp1 = std_course.SelectedItem
dp2 = std_batch.SelectedItem
query = "select roll_no from student where course='" & dp1 & "' and batch='" & dp2 & "'"

ds = obj_data_access.retrieve(query, "student")
rowcount = ds.Tables("student").Rows.Count
If (rowcount = 0) Then
i = 1
Else
query1 = "select max(roll_no) from student where course='" & dp1 & "' and batch='" & dp2 & "'"

ds = obj_data_access.retrieve(query1, "student")
rowcount = ds.Tables("student").Rows.Count
i = ds.Tables(0).Rows(0).Item("roll_no")
i=i+1
End If


std_roll.Text = i