can't connect to interbase using VB.NET - vb.net

i'm pretty new in VB.NET.
i'm trying to connect INTERBASE database (local) and get an error:
I've tried many things and nothing helped.
can't figure out what am I doing wrong or missed
Imports FirebirdSql
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim query As String = "select * from EMPLOYEE"
Dim csb As FbConnectionStringBuilder
Dim cnn As New FbConnection
csb = New FbConnectionStringBuilder()
csb.DataSource = "LOCALHOST"
csb.ServerType = 0
csb.Database = "c:\db\office.gdb"
csb.UserID = "SYSDBA"
csb.Password = "masterkey"
cnn = New FbConnection(csb.ToString)
Dim da As New FirebirdSql.Data.FirebirdClient.FbDataAdapter(query, cnn)
Dim ds As New DataSet
Dim dt As New DataTable
Try
cnn.Open()
da.Fill(dt)
cnn.Close()
cnn.Dispose()
Dim ans As String
If dt.Rows.Count > 0 Then
For Each row As DataRow In dt.Rows
ans = Convert.ToString(row.Item(1))
TextBox1.Text = ans
Next
Else
TextBox1.Text = "Record Not Found"
End If
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Error")
End Try
End Sub
End Class

You cannot use FirebirdClient to connect to InterBase. Firebird and InterBase are not the same.

So...!!!
After digging the net I finally got it working!
Installed "Firebird_ODBC_2.0.3.154_Win32.exe" Downloaded from http://www.firebirdsql.org/en/odbc-driver/
fixed my script:
Dim query As String = "select * from EMPLOYEE"
Dim cnn As New Odbc.OdbcConnection()
Dim estring As New Odbc.OdbcConnectionStringBuilder("DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=masterkey;DBNAME=128.1.7.81:C:\office\db\office.gdb;")
cnn = New OdbcConnection(estring.ToString)
Dim da As New OdbcDataAdapter("select * from EMPLOYEE", estring.ToString)
Dim ds As New DataSet
Dim dt As New DataTable
Try
cnn.Open()
da.Fill(dt)
cnn.Close()
cnn.Dispose()
' (and so one).....
The connection established and I'm happy!
You were right about .NET OLE DB Provider for Firdbird (not working with Interbase), thank you all for the help.
I hope that this thread will help others with this problem.

Related

Vb.net NO value given for one or more given parameters

Dim cmd As OleDbCommand = New OleDbCommand(Sql, con)
Dim strSql As String = "Select EmpName,Count(EmpName) from tblPO where OrderType='" &
"B2B" & "' and POExpireDate < #LogDate Group By EmpName"
Dim tstDate As DateTime = DateTime.Now
Dim dateAsString As String = tstDate.ToString("dd/MM/yy")
cmd.Parameters.AddWithValue("#LogDate", CType(dateAsString, String))
Dim dtb As New DataTable
Using dad As New OleDbDataAdapter(strSql, con)
dad.Fill(dtb)
End Using
con.Close()
I'm working in VB.NET
NO value given for one or more given parameters
error coming while filling datatable..why...how could I fix this.
pls help
Your problem is that you are passing your strSql and the connection to the data adapter but not the command which is what contains the parameter. Pass the command instead
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Using blocks ensure that your database objects are
'Closed And Disposed even if there Is an error.
Dim dtb As New DataTable
Using con As New OleDbConnection("Your connection string")
Dim strSql As String = "Select EmpName,Count(EmpName) from tblPO where OrderType = 'B2B' and POExpireDate < #LogDate Group By EmpName;"
Using cmd As OleDbCommand = New OleDbCommand(strSql, con)
cmd.Parameters.Add("#LogDate", OleDbType.Date).Value = DateTime.Now
'On the next line pass the command, no need to pass connection
'because it has already been passed to the constructor of the command
Using dad As New OleDbDataAdapter(cmd)
dad.Fill(dtb)
End Using
End Using
End Using
End Sub

how to insert multiple records in Access database using VB.NET

I am trying learn how to use Access within VB.NET so i tried to make a simple application using an Access Database that can be used as a dictionary where someone can add some words int the database and then he can search for them.
My db contains two tables one with Word | Description and another one with Word | Synonym
The issue is that one word may have more than one Synonyms so i was thinking i could type all the synonyms in a textbox and using Regex.Split(" ") to split them and insert them in a loop. Can this be done with OleDbParameters?
This is what i have done so far but it only inserts the last record:
str = "insert into Synonyms ([Word],[Synonym]) values (#word,#synonym)"
cmd = New OleDbCommand(str, myConnection)
cmd.Parameters.Add(New OleDbParameter("Word", CType(txtWord.Text,
String)))
cmd.Parameters.Add("#synonym", OleDbType.VarChar)
Dim syn As String() = Regex.Split(txtSynonyms.Text, " ")
Dim i As Integer = 0
While i < syn.Length()
cmd.Parameters("#synonym").Value = syn(i)
i = i + 1
End While
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
MsgBox("Synonyms for word """ & txtWord.Text & """ added")
txtWord.Clear()
txtSynonyms.Clear()
Catch ex As Exception
MsgBox(ex.Message)
End Try
myConnection.Open()
While i < syn.Length()
cmd.Parameters("#synonym").Value = syn(i)
cmd.ExecuteNonQuery()
i = i + 1
End While
myConnection.Close()
Maybe you will find this helpful.
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim con As New OleDb.OleDbConnection
Dim dbprovider As String
Dim dbsource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim inc As Integer
dbprovider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbsource = "Data Source = C:\your_path_here\Nwind_Sample.accdb"
con.ConnectionString = dbprovider & dbsource
con.Open()
sql = "SELECT * FROM [OrderDetails]"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "OrderDetails")
Dim builder As New OleDbCommandBuilder(da)
Dim dsnewrow As DataRow
dsnewrow = ds.Tables("OrderDetails").NewRow()
dsnewrow.Item(0) = OrderID.Text
dsnewrow.Item(1) = ProductID.Text
dsnewrow.Item(2) = UnitPrice.Text
dsnewrow.Item(3) = Quantity.Text
dsnewrow.Item(4) = Discount.Text
'dsnewrow.Item(6) = True
ds.Tables("OrderDetails").Rows.Add(dsnewrow)
da.Update(ds, "OrderDetails")
End Sub
End Class

datagridview not updating automatically in vb.net

The datagirdview is not updating after immediate in inserting records.
Private Sub updatedgv()
Using congv As OleDbConnection = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;data source=..\library.mdb")
Dim strgv As String = "select * from NormalTransaction where RegNo='" & txt_RegisterNo.Text & "'"
Dim cmdgv As OleDbCommand = New OleDbCommand(strgv, congv)
Dim sdagv As OleDbDataAdapter = New OleDbDataAdapter(cmdgv)
Dim dsgv As DataSet = New DataSet("gvSet")
sdagv.Fill(dsgv)
DataGridView1.DataSource = dsgv
DataGridView1.DataMember = dsgv.Tables(0).TableName
End Using
End Sub
please help me to solve this.

Update a Single cell of a database table in VB.net

I am using MS Access Database. Now I have to update a particular cell value. Here is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
Dim Presc As New System.Text.StringBuilder
Dim prs As String(), j As Integer
prs = Split(txtPrescription.Text, vbCrLf)
For j = 0 To prs.Length - 1
Presc.Append(prs(j))
Presc.Append(",")
Next
Try
str = Trim(lsvCase.SelectedItems(0).Text)
'MessageBox.Show(str)
Dim con As System.Data.OleDb.OleDbConnection
Dim ds As New DataSet
Dim rea As System.Data.OleDb.OleDbDataReader
con = New OleDb.OleDbConnection
Dim da As New System.Data.OleDb.OleDbDataAdapter
con.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source= F:\Sowmya Laptop Backups\sowdb1.accdb;"
con.Open()
Dim cmd As OleDb.OleDbCommand = con.CreateCommand
cmd.CommandText = "UPDATE Casehistory set Prescription =' " & Presc.ToString() & "'"
rea = cmd.ExecuteReader
cmd.ExecuteNonQuery()
da.FillSchema(ds, SchemaType.Mapped)
da.Update(ds, "Casehistory")
con.Close()
Catch ex As Exception
Finally
End Try
End Sub
This code updates all the cells in that column. I want to update only the particular cell having Case_ID = str
Where I have to add the WHERE clause (WHERE Case_ID = " & str & "
I would use command parameters, neater and prevents the SQL injection issue. Something like:
cmd.CommandText = "UPDATE Casehistory set Prescription =#Presc WHERE Case_ID = #CaseID"
cmd.Parameters.AddWithValue("#Presc", Presc.ToString())
cmd.Parameters.AddWithValue("#CaseID",str)
As an aside, having all this code in the button click event is less than ideal. You might want to investigate structuring your app in a more maintainable way - perhaps with a Data Layer for example.
The Where clause should be appended to the end of the OleDbCommmand.CommandText, where you define the Update statement.

duplicate in updating ms access database

Here is the error:
http://screencast.com/t/ZDVhNmJiOTgt
Please help, here is my code:
what can I do to solve this error
Try
If MessageBox.Show("Save and update database?", _
"Confirmation", MessageBoxButtons.YesNo) = _
Windows.Forms.DialogResult.Yes Then
Dim idXs As Integer
Dim dSet As New DataSet
Dim conn As New OleDb.OleDbConnection
Dim strSQL As String
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\ACCESS DATABASE\search.mdb"
conn.Open()
strSQL = "Select * From GH"
Dim da As OleDbDataAdapter
da = New OleDb.OleDbDataAdapter(strSQL, conn)
da.Fill(dSet, "GH") 'fill dataset
'code for editing records
Dim cb As New OleDbCommandBuilder(da)
idXs = Form1.idX 'retrieve index from Form1
dSet.Tables("GH").Rows(idXs).Item(0) = TextBox1.Text
dSet.Tables("GH").Rows(idXs).Item(1) = TextBox2.Text
dSet.Tables("GH").Rows(idXs).Item(2) = TextBox3.Text
dSet.Tables("GH").Rows(idXs).Item(3) = TextBox4.Text
da.Update(dSet, "GH") 'update database
conn.Close() 'close connection
reloadMyMain() 'show new changes in form1 if any
Else
DSET.RejectChanges() 'cancel delete
End If
Catch ex As Exception
MsgBox(ex.ToString) 'show exception message
End Try
you need to check the table in the DB - one of the columns is either indexed and can only contain unique values, or has some other limitation.
you enter a data into that column that it can not hold.
Try to "UPDATE" the Data Manually directly on the table and you will see what is wrong...
It seems you just don't have the file F:\ACCESS DATABASE\search.mdb.
Check the path to your access database file.
The error message that you point to reads:
'F:\ACCESS DATABASE\search.mdb' is not a valid path.
Apparently you mistyped the path to the db in the conn.ConnectString = ... line.