Code:
Imports FirebirdSql.Data.FirebirdClientTo edit a row use this routine:
_____________________________________________________
Public Class Edit
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim connection As FbConnection = New FbConnection("servertype=1;username=sysdba;password=masterkey;database=" & My.Application.Info.DirectoryPath & "\Note.gdb")
connection.Open()
' Start a local transaction.
Dim fbTran As FbTransaction = connection.BeginTransaction()
' Enlist the command in the current transaction.
Dim command As FbCommand = connection.CreateCommand()
command.Transaction = fbTran
command.CommandText = _
"insert into Note" _
& " (Title, Note) values ('" & Replace(Me.TextBox1.Text, "'", "''") & "','" _
& Replace(Me.TextBox2.Text, "'", "''") & "')"
command.ExecuteNonQuery()
command.CommandText = _
"select max(contatore) as maxcount from note"
command.ExecuteNonQuery()
fbTran.Commit()
Dim newCustomersRow As DataRow = Note.DataSet1.Tables("Note").NewRow()
Dim dr As FbDataReader = command.ExecuteReader
dr.Read()
newCustomersRow("counter") = dr.Item("maxcount")
newCustomersRow("Title") = Me.TextBox1.Text
newCustomersRow("Note") = Me.TextBox2.Text
Note.DataSet1.Tables("Note").Rows.Add(newCustomersRow)
connection.Close()
Me.Close()
' main form
Note.Show()
End Sub
End Class
code:
Imports FirebirdSql.Data.FirebirdClientInstead of strings appears Getstring1 function because the application is localized: let see this post in this blog: http://firebird-vbnet.blogspot.it/2015/12/localizing-windows-forms-with-resgenexe.html
____________________________________________________
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim ObjConnection As New FbConnection()
ObjConnection.ConnectionString = "servertype=1;username=sysdba;password=masterkey;database=" & My.Application.Info.DirectoryPath & "\note.gdb"
ObjConnection.Open()
Dim ObjCommand As New FbCommand()
ObjCommand.Connection = ObjConnection
ObjCommand.CommandText = "update note set title='" & Replace(Me.TextBox1.Text, "'", "''") & "', Note='" & Replace(Me.TextBox2.Text, "'", "''") & "'where counter='" & Note.DataGridView1.CurrentRow.Cells("counter").Value & "'"
ObjCommand.ExecuteNonQuery()
Dim customerRow() = Note.DataSet1.Tables("Note").Select("counter ='" & Note.DataGridView1.CurrentRow.Cells("counter").Value & "'")
customerRow(0)("Title") = Me.TextBox1.Text
customerRow(0)("Note") = Me.TextBox2.Text
Note.DataGridView1.Columns("title").HeaderText = GetString1("str6")
Note.DataGridView1.Columns("Note").HeaderText = GetString1("str7")
Note.DataGridView1.Columns("counter").Visible = False
Me.Close()
' main form
Note.Show()
End Sub
End Class
No comments
Post a Comment