Firebird and Visual Basic .Net example code

If you are using Visual Studio or Visual Basic to develop program connect to firebird database server, this might be a good example.

Imports FirebirdSql.Data.FirebirdClient
__________________________________________________________________
Public Class Principale



Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Fdataa As New FbDataAdapter("select*from New_table1", "servertype=1;username=sysdba;password=masterkey;database=" & My.Application.Info.DirectoryPath & "\Giorgio.gdb")

DataSet1.Tables.Add("New_table1")
Me.DataGridView1.DataSource = DataSet1
Me.DataGridView1.DataMember = "New_table1"

Fdataa.Fill(DataSet1, "New_table1")

End Sub


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Nuovo.Show()
End Sub
'To begin the change
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'I used the trim function because would be problems with positioning of the cursor if you will pass from varcahr type to char type and vice versa.
Modifica.TextBox1.Text =

Microsoft.VisualBasic.Trim(DataGridView1.CurrentRow.Cells(0).Value)

Modifica.TextBox2.Text = DataGridView1.CurrentRow.Cells(1).Value


Modifica.Show()
End Sub

'To delete a record

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim mResult
Dim ObjConnection As New FbConnection()
mResult = MsgBox("Si desidera eliminare questo cliente?", _
vbYesNo + vbQuestion, "Conferma eliminazione")
If mResult = vbNo Then
Exit Sub
End If
ObjConnection.ConnectionString = "servertype=1;username=sysdba;password=masterkey;database=" & My.Application.Info.DirectoryPath & "\miodb.gdb"
ObjConnection.Open()
Try
Dim ObjCommand As New FbCommand()
ObjCommand.Connection = ObjConnection

ObjCommand.CommandText = "delete from New_table1 where Clienti='" & Me.DataGridView1.CurrentRow.Cells(0).Value & "'"
ObjCommand.ExecuteNonQuery()
Finally
ObjConnection.Close()
End Try

Me.DataGridView1.Rows.Remove(Me.DataGridView1.CurrentRow)

End Sub
End Class

'To update a record

Imports FirebirdSql.Data.FirebirdClient
______________________________________________________________
Public Class Modifica



Private Sub btnAggiorna_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAggiorna.Click
Dim customerRow() = Principale.DataSet1.Tables("New_table1").Select("Clienti ='" & Principale.DataGridView1.CurrentRow.Cells(0).Value & "'")


Dim ObjConnection As New FbConnection()

ObjConnection.ConnectionString = "servertype=1;username=sysdba;password=masterkey;database=" & My.Application.Info.DirectoryPath & "\miodb.gdb"
ObjConnection.Open()
Try
Dim ObjCommand As New FbCommand()
ObjCommand.Connection = ObjConnection

ObjCommand.CommandText = "update New_table1 set Clienti='" & Me.TextBox1.Text & "', Spesa='" & Me.TextBox2.Text & "' where Clienti='" & Principale.DataGridView1.CurrentRow.Cells(0).Value & "'"
ObjCommand.ExecuteNonQuery()
Finally
ObjConnection.Close()
End Try

customerRow(0)("Clienti") = Me.TextBox1.Text
customerRow(0)("Spesa") = Me.TextBox2.Text

Me.Close()
Principale.Show()
End Sub
End Class

'To insert e new record

Imports FirebirdSql.Data.FirebirdClient
____________________________________________________________
Public Class Nuovo


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ObjConnection As New FbConnection()

ObjConnection.ConnectionString = "servertype=1;username=sysdba;password=masterkey;database=" & My.Application.Info.DirectoryPath & "\miodb.gdb"
ObjConnection.Open()
Try
Dim ObjCommand As New FbCommand()
ObjCommand.Connection = ObjConnection
ObjCommand.CommandText = "insert into New_table1 (Clienti, Spesa) values ('" & TextBox1.Text "','" & TextBox2.Text & "')"
ObjCommand.ExecuteNonQuery()
Finally
ObjConnection.Close()
End Try



Dim newCustomersRow As DataRow = Principale.DataSet1.Tables("New_table1").NewRow()
newCustomersRow("Clienti") = TextBox1.Text
newCustomersRow("Spesa") = TextBox2.Text
Principale.DataSet1.Tables("New_table1").Rows.Add(newCustomersRow)



Me.Close()
Principale.Show()
End Sub

End Class

Example from : http://firebird-vbnet.blogspot.com/2006/12/esempi-di-codice.html

Comments

Popular posts from this blog

Fedora 19 with kernel 3.10 fail to install vmplayer module.

Setup mail server with ldap authentication in docker

How to allow non root user to execute hping command ?