Hi,I have problem on my code,it will not insert to the database can you pease help me on this.Thank you in advance.
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Private m_con As New SqlConnection
Private m_DA As SqlDataAdapter
Private m_CB As SqlCommandBuilder
Private m_dataTable As New DataTable
Private m_rowPosition As Integer = 0
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
m_con.Close()
m_con.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\book.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
m_con.Open()
m_DA = New SqlDataAdapter("select * from book", m_con)
m_CB = New SqlCommandBuilder(m_DA)
m_DA.Fill(m_dataTable)
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
Me.Close()
End Sub
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
m_DA.Fill(m_dataTable)
Dim adNewRow As DataRow = m_dataTable.NewRow()
adNewRow("FIRSTNAME") = txtname.Text
adNewRow("LASTNAME") = txtlname.Text
m_dataTable.Rows.Add(adNewRow)
m_DA.Update(m_dataTable)
m_rowPosition = m_dataTable.Rows.Count - 1
End Sub
End Class