Я просто использую базы данных. Я создал класс, который, похоже, работает. У меня есть функция, которую я создал с помощью учебника. он является частью файла DataAccess.class. То, что я смущен, - это как;Вызов функции из класса
A) Включите файл DataAccess.class в форме я работаю и B) Вызов функции вставки с кнопкой
Вот код
Public Shared Function InsertNewRecord(ByVal item1 As String, ByVal item2 As String, ByVal item3 As String) As Boolean
'Create the objects we need to insert a new record
Dim cnInsert As New OleDbConnection(GetConnectionString("YourConnName"))
Dim cmdInsert As New OleDbCommand
Dim query As String = "INSERT INTO YourTable(column1,column2,column3) VALUES(@item1,@item2,@item3)"
Dim iSqlStatus As Integer
'Clear any parameters
cmdInsert.Parameters.Clear()
Try
'Set the OleDbCommand Object Properties
With cmdInsert
'Tell it what to execute
.CommandText = query
'Tell it its a text query
.CommandType = CommandType.Text
'Now add the parameters to our query
'NOTE: Replace @value1.... with your parameter names in your query
'and add all your parameters in this fashion
.Parameters.AddWithValue("@value1", item1)
.Parameters.AddWithValue("@value2", item2)
.Parameters.AddWithValue("@value3", item3)
'Set the connection of the object
.Connection = cnInsert
End With
'Now take care of the connection
HandleConnection(cnInsert)
'Set the iSqlStatus to the ExecuteNonQuery
'status of the insert (0 = failed, 1 = success)
iSqlStatus = cmdInsert.ExecuteNonQuery
'Now check the status
If Not iSqlStatus = 0 Then
'DO your failed messaging here
Return False
Else
'Do your success work here
Return True
End If
Catch ex As Exception
MsgBox(ex.Message, "Error")
Finally
'Now close the connection
HandleConnection(cnInsert)
End Try
End Function
Спасибо заранее
Да, он говорит, что его не объявлено – Rabastan
Такие ответы, которые действительно являются комментариями, запрещены в правилах SO – ElektroStudios