please people your help will be appreciated.
i have a table with data definition:

column Datatype
BookID int
AuthorFirstname nvarchar(20)
AuthorSecondName nvarchar(20)
BookTitle nvarchar(50)
Price nvarchar(50)

My problem is that i can't see the inserted data in my table
Below is the whole code:

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.Exception
Imports System.Data
Imports System.Data.SqlClient
Public Class Form2
    Dim connection As SqlConnection = Nothing
    Dim conn As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Libridata.mdf;Integrated Security=True;User Instance=True"


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim firstname As String = txtbx1.Text
        Dim secname As String = txtbx2.Text
        Dim title As String = txtbx3.Text
        Dim price As String = txtbx4.Text
        Dim Idd As Integer = txtbx5.Text

        Try
            Dim conn As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Libridata.mdf;Integrated Security=True;User Instance=True"
            connection = New SqlConnection(conn)
            connection.Open()
            Dim sql As String = "INSERT INTO Libritable( BookID,AuthorFirstname,AuthorSecondName,BookTitle,Price) VALUES (@BookID,@AuthorFirstname, @AuthorSecondName, @BookTitle, @Price)"
            Dim cmd As SqlCommand = New SqlCommand(sql, connection)
            cmd.Parameters.AddWithValue("@AuthorFirstname", firstname)
            cmd.Parameters.AddWithValue("@AuthorSecondName", secname)
            cmd.Parameters.AddWithValue("@BookTitle", title)
            cmd.Parameters.AddWithValue("@Price", price)
            cmd.Parameters.AddWithValue("@BookID", Idd)
            cmd.ExecuteNonQuery()
            MessageBox.Show("book added successfully!")
        Catch ae As SqlException
            MessageBox.Show(ae.Message.ToString())
        End Try


    End Sub
End Class

Since you're not getting an error, my first guess is that you're looking at the wrong database. Instead of looking for the data in the database that's in your source code (in IDE), look at the one in your BIN/Debug folder.

I gathered this from your connection string using |DataDirectory| which means that it's running either in the specified data directory (not as common) or running in the same directory as your executable/assembly.

So, if you want to see the data entered, check your bin/debug folder and look at the database that was copied to that directory. Also, if the database is overwritten every time you rebuild, the data won't persist between runs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.