Из записи richtexbox1 сохранение временно сохранено не постоянно в базе данных access
я сделал запись из Richtextbox1, и когда я нажал кнопку Сохранить, Она была успешно сохранена, но когда я закрыл отладку и снова запустил ее, ее не было в Datagridview1, а также в базе данных Ms Access, пожалуйста, помогите мне в этом...
Примечание : когда я нажимаю кнопку AddNew без ввода значения, она говорит: "ExecuteReader требует открытого и доступного соединения. Текущее состояние соединения-закрыто."
Что я уже пробовал:
Imports System.Data.OleDb Public Class SongEntry Dim Provider As String Dim dataFile As String Dim connString As String Dim myConnection As OleDbConnection = New OleDbConnection Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click TextBox1.Clear() TextBox2.Clear() TextBox3.Clear() TextBox4.Clear() TextBox5.Clear() End Sub Private Sub SongEntry_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click Provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" dataFile = "C:\Users\User\Desktop\Worship\Worship\bin\Debug\Song.accdb" connString = Provider & dataFile myConnection.ConnectionString = connString myConnection.Open() Dim str As String str = "Insert into MAS_SONGS([SM_CODE],[SM_EDESC],[SM_TDESC],[SM_SONGL1],[SM_SONGL2]) values (?,?,?,?,?)" Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection) cmd.Parameters.Add(New OleDbParameter("SM_CODE", CType(TextBox3.Text, String))) cmd.Parameters.Add(New OleDbParameter("SM_EDESC", CType(TextBox1.Text, String))) cmd.Parameters.Add(New OleDbParameter("SM_TDESC", CType(TextBox2.Text, String))) cmd.Parameters.Add(New OleDbParameter("SM_SONGL1", CType(TextBox4.Text, String))) cmd.Parameters.Add(New OleDbParameter("SM_SONGL2", CType(TextBox5.Text, String))) Try cmd.ExecuteNonQuery() cmd.Dispose() myConnection.Close() TextBox1.Clear() TextBox2.Clear() TextBox3.Clear() TextBox4.Clear() TextBox5.Clear() Catch ex As Exception MsgBox("saved") End Try End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Me.Close() End Sub Private Sub SongEntry_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Escape Then Me.Close() End If End Sub Private Sub TextBox4_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox4.KeyPress If e.KeyChar = Convert.ToChar(1) Then DirectCast(sender, TextBox).SelectAll() e.Handled = True End If End Sub Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress If e.KeyChar = Convert.ToChar(1) Then DirectCast(sender, TextBox).SelectAll() e.Handled = True End If End Sub Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress If e.KeyChar = Convert.ToChar(1) Then DirectCast(sender, TextBox).SelectAll() e.Handled = True End If End Sub Private Sub TextBox3_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox3.KeyPress If e.KeyChar = Convert.ToChar(1) Then DirectCast(sender, TextBox).SelectAll() e.Handled = True End If End Sub Private Sub TextBox5_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox5.KeyPress If e.KeyChar = Convert.ToChar(1) Then DirectCast(sender, TextBox).SelectAll() e.Handled = True End If End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click MASSONGSBindingSource.RemoveCurrent() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try mySQL = "Select SM_CODE from MAS_SONGS ORDER BY SM_CODE DESC" ConnDB() myCommand = New OleDbCommand(mySQL, myConnection) myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) If myReader.Read = True Then TextBox3.Text = Val(myReader(0)) + 1 Else TextBox3.Text = 300001 End If Catch ex As Exception MsgBox(ex.Message) Finally myCommand.Dispose() myConnection.Close() End Try End Sub Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged End Sub End Class