**hello all, i am creating a programme for my institute which helps in their administrative process. i am using visual studio(basic) 2010. which is connected with ms access database (abcdata.accdb) the database is having table called session with columns sessionID,sessioncode,sessionname. * sessionID data = 1,2,3,4 * sessioncode data = 13,14,15,16 * sessionname data = 2013,2014,2015,2016 the another is having table called course with a columns courseID, coursecode, coursename * courseID data = 1,2,3,4 * coursecode data = 01,02,03,04 * coursename data = ba,ma,bsc.msc the other table called courseyear with colums courseyearID, courseyearcode, courseyearname. * courseyearID = 1,2,3,4 * courseyearcode = 01,02,03,04 * courseyearname = I,II,II,IV in vb a form is having 3 comboboxes and one textbox. i am pulling data from database to my comboboxes with this code:** **Private Sub loadcourse()** Dim OleDBC As New OleDbCommand Dim OleDBDR As OleDbDataReader With OleDBC .Connection = conn .CommandText = "SELECT coursename FROM tblcourse" End With OleDBDR = OleDBC.ExecuteReader cmbcourse.Items.Clear() If OleDBDR.HasRows Then While OleDBDR.Read cmbcourse.Items.Add(OleDBDR.Item(0)) End While End If End Sub **Private Sub loadcourseyear()** Dim OleDBC As New OleDbCommand Dim OleDBDR As OleDbDataReader With OleDBC .Connection = conn .CommandText = "SELECT courseyearname FROM tblcourseyear" End With OleDBDR = OleDBC.ExecuteReader cmbcourseyear.Items.Clear() If OleDBDR.HasRows Then While OleDBDR.Read cmbcourseyear.Items.Add(OleDBDR.Item(0)) End While End If End Sub * loadsession(in the same manner) **now i just want to create a unique ID based on comboboxes selection like this:** * if cmbsession.select = 2013 * and if cmbcourse.select = ba * and if cmbcourseyear.select = II then the textbox named txtrollnumber must fill like this: **130102** **i tried with this code but it is showing number like this : 010213** Private Sub cmbcourseyear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbcourseyear.SelectedIndexChanged Try ' Open connection Dim sqlQRY As String = "select * from tblcourseyear where courseyearname='" + cmbcourseyear.Text + "'" 'create data adapter Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlQRY, conn) 'create dataset Dim ds As DataSet = New DataSet 'fill dataset da.Fill(ds, "tblcourseyear") 'get data table Dim dt As DataTable = ds.Tables("tblcourseyear") 'display data Dim row As DataRow For Each row In dt.Rows txtrollnumber.Text = row("courseyearcode") + txtrollnumber.Text Next row If ds.Tables("tblcourseyear").Rows.Count = 0 Then MessageBox.Show("Sorry No Record Found Please Try Again!", " You Software name ", MessageBoxButtons.OK, MessageBoxIcon.Information) End If ' Close connection conn.Close() Catch ex As OleDbException MessageBox.Show("Customer Not found" + ex.Message) End Try End Sub with this i also want to add a number after 130102 like this : 0001,0002,0003,0004 and so on....... this number must genetate on the basis of the IDs saved in the datable i.e.if 1301020001 is exist in datatable row then the last 4 digets must change with 0002.and in i select **130201** if 1302010001 or last highest number from last 4 match with first 6 degits is exist than the number must change to +1 on last 4 degits. ****i tried with this code which i got from your fourm but is is generating code at form load event.** Private Function GenerateID() As String Dim value As String = "00000" Dim studentID As String Try ' Fetch the latest ID from the database con.Open() mycmd = New OleDbCommand("SELECT TOP 1 studentID FROM tblstudentsregistration ORDER BY studentID DESC", Con) mydr = mycmd.ExecuteReader(CommandBehavior.CloseConnection) If mydr.HasRows Then mydr.Read() value = mydr.Item("studentID") End If mydr.Close() 'Increase the ID by 1 value += 1 ' Because incrementing a string with an integer removes 0's ' we need to replace them. If necessary. If value <= 9 Then 'Value is between 0 and 10 value = "00000" & value ElseIf value <= 99 Then 'Value is between 9 and 100 value = "0000" & value ElseIf value <= 999 Then 'Value is between 999 and 1000 value = "000" & value End If Catch ex As Exception ' If an error occurs, check the connection state and close it if necessary. If con.State = ConnectionState.Open Then con.Close() End If value = "00000" End Try Return value End Function other then this u can see i want this because i am trying to create a database which must save the students data year wise, so that whenever we need to know a detail any students then we can find with query. sorry if not explaned in better way because i am very new in this please help me thanks in advance
All 2 Replies
Be a part of the DaniWeb community
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.