how to connect SQL and R.Net? - sql

I want to connect SQL database from R.Net. I am using R.Net from vb.net.
Is it possible? If it possible how?
Using vb.net i have added some .DLL file (R.Net.dll,RdotNET.dll) which will help to work R.Net and i did some coding to find sum.
code:
Imports RdotNET
Public Class Form1
Dim engine As REngine
Dim sum As Double
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
REngine.SetDllDirectory("#C:\Program Files\R\R-2.12.0\bin\i386")
engine = REngine.CreateInstance("RDotNet")
engine.EagerEvaluate("sum<- 5 + 6")
sum = engine.GetSymbol("sum").AsNumeric.First()
MessageBox.Show(sum.ToString)
End Sub
now i need to connect to Sql. i need to read a table data and display it in a my app
sorry for my bad English.

Writing R code that uses R.NET to call a .NET connection to a SQL database seems like an overcomplicated way of doing things. Unless your use case demands this (edit your question to explain what you are doing), I recommend using one of the many R packages that connect directly to SQL databases. Take a look at dbConnect, RMySQL, RPostgreSQL, RODBC, RSQLite or RpgSQL, depending upon what sort of database it is.

Related

How to save, edit, and create new record in Access Query with VB.NET

I have a task from school to make a simple program with VB.NET and currently having an issue now. I've connected my MS Access Query (Query, not Table) with my form in VS2015. The program run smoothly, but when I want to update the data, this error message came up
TableAdapterManager contains no connection information. Set each TableAdapterManager TableAdapter property to a valid TableAdapter instance.
I used this following code to update the database
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.Validate()
Me.JoblistBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Joblist)
End Sub
I need this program to run as late as Thursday.
Does anyone know how to fix this problem? Thanks before.

Access database connecting to VS but no data showing and runtime error

Trying to use an access database with Visual studio 15. After failure I found a number of tutorials and followed them with a new project and new database.
The database is connecting but the data inside the database won't display (although no error) and even using the built in save function in VB results in a run time error.
If anyone can point me in the right direction I'd be grateful. Code below.
Public Class Form1
Private Sub CustomersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles CustomersBindingNavigatorSaveItem.Click
Me.Validate()
Me.CustomersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.CustomersDataSet) 'Error is here****
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomersDataSet.Customers' table. You can move, or remove it, as needed.
Me.CustomersTableAdapter.Fill(Me.CustomersDataSet.Customers)
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
End Sub
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
End Sub
End Class
The error message I get is An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Unspecified error.
Here is a video that I made a while ago that should be able to help you, If you have any questions about it, i can definitely help you out.
https://www.youtube.com/watch?v=vvzY0LsAUNE
Also do you definitely need to use Access? I would recommend using an SQL database because when you publish your program, the end user may have to have a link to your access database in the same spot as yours, which can be a pain.
Nevertheless here is a video i also made regarding setting up an SQL database via Visual Studio.
https://www.youtube.com/watch?v=NLs44hxV514
If you have any issue, leave a comment and i will be happy to help you out :)
Keep In Mind
Don't forget that you need to also have a Number/unique word/or something a like in the Primary key column even if you haven't added any details to the database. eg Name and so on. If not your program may crash, so you could use the Try statement to fix this issue if the Primary Key column is left empty.

Query Access Visual Basic

I am trying to figure out how to query an access db using visual basic but I'm looking for a little explanation on how this actually works.
What I'm confused about is that I state a command SELECT * FROM PI (PI Being the table) but then directly below that, I'm saying that TextBox1.Text = theDataTable.Rows(0).Item(1).
I'm just wondering why I have a query command and then a seperate command that is going to a specified Row and Item....any help is much appreciated!
Imports System.Data.OleDb
Public Class Form1
Dim theConnectionString As New OleDbConnection
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
txtSQL.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
theConnectionString.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Marc Wilson\Documents\FiddleFuckDB.accdb"
theConnectionString.Open()
Dim theDataSet As New DataSet
Dim theDataTable As New DataTable
theDataSet.Tables.Add(theDataTable)
Dim theDataAdapter As New OleDbDataAdapter
theDataAdapter = New OleDbDataAdapter("SELECT * FROM PI", theConnectionString)
theDataAdapter.Fill(theDataTable)
TextBox1.Text = theDataTable.Rows(0).Item(1)
theConnectionString.Close()
End Sub
End Class
Like this
"SELECT * FROM PI Where FieldName = '" & TextBox1.Text & "'"
assumed that your field type is not numeric
Since you're using an ADO.NET DataTable - that object consist of Rows collection and each row in turn consists of Items collection. So in order to get to a specific value you need to use
Table.Rows(X)(Y)
notation. Even if your query returns a single value - you would use this approach. Looking at your code and Items(1) especially, it looks like your query returns at least 2 columns.
If you're interested in a single value only, consider specifying a single column name in your query, make sure that it returns a single row (e.g. by adding WHERE clause to your query) and use ExecuteScalar ADO.NET command, which, unlike Fill and DataTable returns a single value only.
Not 100% sure I undertand the question, but hopefully this helps:
The query command is fetching all of the records from the table in your database. The Rows() and Item() methods fetch a particular field from a particular record (in this case, the second field of the first record).
The Text property of your TextBox cannot display the entire table on it's own: the DataTable is a fairly complicated data strucutre. TextBoxes require a string (or something like one).
SELECT * FROM PI tells the database engine which data it should retrieve from the underlying database table that exists on-disk.
You're using the DataTable class which represents data in-memory: the DataAdapter class reads data from disk (using the SQL statement) and copies it into memory, where you then use the Rows(0).Item(1) command to get a copy of the data already in memory.
The alternative is to use DataReader which is more direct, often simpler. In your case I don't see why you're using the DataTable class because DataReader will suit you fine.

Creating Oracle Connection causes error in COM class retrieval

I am writing an application in VB.NET that requires that I query an Oracle database using the Oracle Data Access Client. I then use something called the SCAPI interface to access the metadata of an application we use for data modeling.
I've simplified the problem down to just two functions that are executed by clicking buttons on a form.
This function is executed when I click a button on the form. It creates an oracle connection but doesn't actually execute any queries (because I've commented the rest out and still get the error):
Private Sub btnDisplayDirectories_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayDirectories.Click
Dim ModelMart As String = "Data Source=...;User Id=...;Password=...;"
Dim OraConn As New OracleConnection(ModelMart)
OraConn.Open()
OraConn.Close()
OraConn.Dispose()
End Function
This function just creates the application object using the SCAPI interface:
Private Sub btnOpenModel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenModel.Click
Dim oAPI As New SCAPI.Application
End Sub
There is no issue if I fire up the application, and click on btnOpenModel first, then click on btnDisplayDirectories. If I click on btnDisplayDirectories, then I click on btnOpenModel, I get an error on the first line of btnOpenModel that says:
Retrieving the COM class factory for component with CLSID {2B2219EB-EDE7-49EE-BB89-5A0B4A398A63} failed due to the following error: 80004005.
I've actually experimented and I don't even have to open the Oracle connection to get this error, just defining the Oracle Connection causes the error.
I solved the problem by creating the SCAPI.Application object as a global variable. This causes SCAPI to get its hands on whatever resources it requires before the database objects do. I wasn't able to figure out exactly why SCAPI and Oracle/ODBC assemblies don't play nice with each other.

Using VB.net DataGrid view to interact with SQL DB. Update/Delete/Add

Setup Information
I have "Form1" with a DataGrid View ("DataGridView1") which populates with Data from an SQL server table.
It's a simple table, with about 10 records.
The table used is "jamesTestVBlol"
The dataset is named "DataSetJames.xsd"
I believe the table adaptor is called "JamesTestVBlolTableAdaptor"
Question
Is there a way, I can update a record and send these changes back to the server.
e.g. Column 1, record 1 I would like to change to "TEST" and update this table on the server.
The only code I have is:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DataSetJames.jamesTestVBlol' table.' You can move, or remove it, as needed.
Me.JamesTestVBlolTableAdapter.Fill(Me.DataSetJames.jamesTestVBlol)
End Sub
End Class
Could anyone help me with where I need to look?
I've tried to read several online tutorials, but generally they are above my head.
Thanks,
James.