i want to have a student no. in every course example in course Computer Technician the student no. should like this COMTECH001 and course Computer Science the student no. should like this COMSCI001 how do increment it by 1 in every student enroll if he choose course from combo box
i have no idea in codes from this thanks
Loading
Satyapriya NayakPosted Apr 1, 2013, 12:19 AM
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.OleDb
Namespace Dynamic_generate_id
Public Partial Class Form1
Inherits Form
Private ConnectionString As String = System.Configuration.ConfigurationSettings.AppSettings("dsn")
Private com As OleDbCommand
Private str As String
Private count As Integer
Public Sub New()
InitializeComponent()
End Sub
Private Sub btn_save_Click(sender As Object, e As EventArgs)
Dim con As New OleDbConnection(ConnectionString)
con.Open()
str = "insert into caste(cast_code,cast_desc) values('" & lbl_castecode.Text.Trim() & "','" & txt_castename.Text.Trim() & "')"
com = New OleDbCommand(str, con)
com.ExecuteNonQuery()
con.Close()
MessageBox.Show("Records successfully Inserted")
txt_castename.Text = ""
autogenerated()
End Sub
Private Sub autogenerated()
Dim con As New OleDbConnection(ConnectionString)
str = "select count(*) from caste"
com = New OleDbCommand(str, con)
con.Open()
count = Convert.ToInt16(com.ExecuteScalar()) + 1
lbl_castecode.Text = "ACT00" & count.ToString()
lbl_castecode.Enabled = False
con.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs)
autogenerated()
End Sub
End Class
End Namespace
Jignesh TrivediPosted Apr 1, 2013, 12:18 AM
Hi Mark,
Please refer below quesion post by you.
this might help you.
http://www.c-sharpcorner.com/Forums/Thread/205078/incrementing-from-sql-with-VB-Net.aspx