hello i used the code..bt m gettin the same value of 1 aftr the form loads..
the value is not being incremented..
and m a beginner so dis is d overall code and i have done d module part too..plz help

Comments
Improper use of words, especially when the one asking the question.

post the code you have here. and explain what you are doing. dont attached a docx ..

ok m makin a projct vch has a form of vb.net..a library record based one..so..i need to generate bookids and membership ids as an autogenerated no vch has to be b automatically comin from d database so i hav written d code vch goes like dis

////Code

Imports System.Data
Imports System.Data.SqlClient

Public Class frm8

    Dim sql As String





    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Hide()
        frm7.Show()
    End Sub


   Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        If txtBookId.Text <> " " Then
            If txtTitle.Text <> " " Then
                If txtAuthor.Text <> " " Then
                    If txtPub.Text <> " " Then
                        If txtPrice.Text <> " " Then
                            Dim connectionstring As String
                            Dim connection As SqlConnection
                            Dim ds As New DataSet
                            Dim cmd As New SqlCommand
                            Dim button As DialogResult

                            connectionstring = "Data Source=.;Initial Catalog=project;Integrated Security=True"
                            connection = New SqlConnection(connectionstring)
                            Try
                                connection.Open()
                                button = MessageBox.Show("Save changes?", "Confirm data", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
                                If button = Windows.Forms.DialogResult.OK Then
                                    sql = "insert into books1 (b_title,b_author,b_price,b_publisher)values('" & txtTitle.Text & "','" & txtAuthor.Text & "'," & txtPrice.Text & ",'" & txtPub.Text & "')"
                                    cmd = New SqlCommand(sql, connection)
                                    If cmd.ExecuteNonQuery() Then
                                        MessageBox.Show("Succesfully saved", "Saved", MessageBoxButtons.OK)
                                        clear()
                                        GenerateNotaId()
                                    Else
                                        MessageBox.Show("Retry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                                    End If
                                Else
                                    Me.Show()
                                End If
                                connection.Close()
                            Catch ex As Exception
                                MsgBox(ex.ToString)
                            End Try

                        Else

                            MessageBox.Show("Please enter the price", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                            txtPrice.Focus()
                        End If
                    Else
                        MessageBox.Show("Please enter the publisher", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                        txtPub.Focus()
                    End If
                Else
                    MessageBox.Show("Please enter the author", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    txtAuthor.Focus()
                End If
            Else
                MessageBox.Show("Please enter the title", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                txtTitle.Focus()
            End If
        Else
            MessageBox.Show("Please enter the bookid", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            txtBookId.Focus()
        End If



    End Sub
    Private Sub clear()

        txtTitle.Text = " "
        txtAuthor.Text = " "
        txtPub.Text = " "
        txtPrice.Text = " "



    End Sub

   
    Private Sub frm8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ProjectDataSet1.Books1' table. You can move, or remove it, as needed.
        Me.Books1TableAdapter.Fill(Me.ProjectDataSet1.Books1)
        'TODO: This line of code loads data into the 'ProjectDataSet4.Books' table. You can move, or remove it, as needed.
        Me.BooksTableAdapter.Fill(Me.ProjectDataSet4.Books)
        clear()

    End Sub

    Public Sub GenerateNotaId()
       
        Dim myReader As SqlDataReader
        conn = GetConnect()
        conn.Open()
        Dim temp As Integer
        Try
            Dim sql As String = "SELECT MAX(bookidID) AS 'KODE' FROM Books1 "
            Dim comm As SqlCommand = New SqlCommand(sql, conn)
            myReader = comm.ExecuteReader
            If myReader.HasRows Then
                While myReader.Read()
                    temp = myReader.Item("KODE") + 1
                End While
            End If
            myReader.Close()
        Catch ex As Exception

        End Try
        conn.Close()
        If temp = 0 Then
            txtBookId.Text = 1
        Else
            txtBookId.Text = String.Concat(temp)
        End If
    End Sub
End Class

Edited 5 Years Ago by __avd: Added [code] tags.

This article has been dead for over six months. Start a new discussion instead.