Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click conn.Open() Dim query As String = "insert into Academic(Id,Session)values(@Id,@Session)" If TxtSession.Text = "" Then MsgBox("Please Insert the Session ", MsgBoxStyle.Information, "Grading System") TxtSession.Text = "" txtSessionId.Text = "" TxtSession.Focus() Else Dim query1 As String = "select Id,Session from Academic Where Session='" & TxtSession.Text & "'" cmd1 = New SqlCommand(query1, conn) dr = cmd1.ExecuteReader() If dr.Read = False Then dr.Close() Try Try Dim no As integer Dim k as integer cmd = New SqlCommand("select count(*) from Academic", conn) no = cmd.ExecuteScalar no = CInt(no) + 1 If no > 0 And no <= 9 Then k = ("A000" + no) ElseIf no > 9 And no <= 99 Then k = ("A00" + no) ElseIf no > 99 And no <= 999 Then k = ("A0" + no) Else k = ("A" + no) End If Catch ex As Exception MsgBox(ex.Message) End Try cmd = New SqlCommand(query, conn) dr.Close() cmd.Parameters.AddWithValue("@Id", (k)) cmd.Parameters.AddWithValue("@Session", (TxtSession.Text)) cmd.ExecuteNonQuery() MsgBox("Session Inserted", MsgBoxStyle.Information, "Grading System") ds.Clear() conn.Close() LoadDataInDataGrid() TxtSession.Text = "" TxtSession.Focus() Catch ex As Exception MessageBox.Show(ex.ToString()) Finally If conn.State = ConnectionState.Open Then conn.Close() End If End Try Else MsgBox("Record Exists", MsgBoxStyle.Information, "Grading System") TxtSession.Focus() txtSessionId.Text = "" End If End If conn.Close() End Sub
k
int
Id
no
substring
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)