I have:
1) C# WPF DataGrid
2) MS Access db that include one table ("Temp")!
I already read a lot of forums and arcticles but I'm not find an answer!
I want to add/edit/delete data in MS Access DB using DataGrid!
I'm tried these code but it's doesnt work!
private void Button_Click_3(object sender, RoutedEventArgs e)
{
if (_dataSet != null && _dataSet.Tables[0] != null && _dataSet.HasChanges(DataRowState.Modified))
{
DataTable dt = _dataSet.Tables[0].GetChanges(DataRowState.Modified);
adapter.Update(dt);
}
adapter.Update(_dataSet.Tables["Temp"]);
}
I'm from Ukraine so translalte u!
I have an error (I'm hope I do it right):
"Dynamic SQL generation for the DeleteCommand is not supported for the SelectCommand, does not return any key column information"
Error like this always return when use update or ad data to DataGrid!
PLEASE, Help me!
Thanks You for a all!
Maybe you will use ORM (object relational mapping) for data access. For .NET exist: Entity Framework, Fluent Nhibernate, Dapper (micro-orm) - maybe beast options for you because it is very simple. Also note MVVM pattern (beast option for WPF). Good article with example: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
A have an answer!
To work this code he need a key cell(column)!
If there is not, commandBuilder can't get a default comands, so you always get an errors! Here are code:
adapter = new OleDbDataAdapter(comand, con);
_dataSet = new DataSet();
adapter.Fill(_dataSet, "TargetAndProbability");
cb = new OleDbCommandBuilder(adapter);
cb.QuotePrefix = "[";// it's need if your cells contains others symbols
cb.QuoteSuffix = "]";
Than all very simple!
adapter.Update(_dataSet, "TargetAndProbability");
Related
I want to write some custom code to perform the 'Link Table Manager' operation programatically. I have MS-Access database which is currently referencing external data from Excel,MS-Access and SQL server.
Before executing a Macro on my MS-Access database, I want to re-link the external data sources or provide new location of the data-source in case there is change in the location of the data source.
I have a table in MS-Access database which is Linked to an external SQL data source(Test database). Now I want it to be linked to Production Database. I have tried the following code but it is throwing a COM-Exception with error description as 'ODBC--connection to 'EmployeeConnectionForSQL' failed.'
public void performLinkTableMangerOperationForSQL()
{
string CurrentDatabasePath = #"D:\UDTDatabase\InternalDatabase.accdb";
Microsoft.Office.Interop.Access.Dao.DBEngine DAO = new Microsoft.Office.Interop.Access.Dao.DBEngine();
Microsoft.Office.Interop.Access.Dao.Database db;
Microsoft.Office.Interop.Access.Dao.TableDefs dt;
db = DAO.OpenDatabase(CurrentDatabasePath);
dt = db.TableDefs;
// Refreshing link for Sql server external table with DSN.
string sqlSource = #"DATABASE=Employee;";
string DSNName = "EmployeeConnectionForSQL;";
string sqlNewConnectionString = #"ODBC;FileDSN=" + DSNName + sqlSource;
foreach (Microsoft.Office.Interop.Access.Dao.TableDef table in dt)
{
string name = table.Name;
if (table.Name == "dbo_Employees")
{
table.Connect = sqlNewConnectionString;
table.RefreshLink();
}
}
db.Close();
}
That FileDSN is clearly invalid. A FileDSN should point to a .dsn file. If you want to use a normal DSN, use DSN=, not FileDSN=. Since there's an invalid DSN, you can't relink.
I highly recommend you go DSNless, and just use a connection string, but providing a valid FileDSN should work too.
I'm trying to read all fields in a CSV file using GDAL v2.1.3
Using this command it is working:
ogrinfo -ro -al -so test.csv -oo X_POSSIBLE_NAMES=Lon* -oo Y_POSSIBLE_NAMES=Lat* -oo KEEP_GEOM_COLUMNS=NO
Now I need to do this in my C# application.
Because I need to send -oo (open options) I cannot use Ogr.Open(), but I should use Gdal.OpenEx(), right?
OpenEx returns a Dataset, which I somehow need to convert to an ogr datasource so I can use GetLayerByIndex(), GetFieldCount() and GetFieldDefn() but I can't get it to work.
Looking at numerous Python example it seems in Python no conversion is needed.
This is my C# code:
var openOptions = new[]
{
"X_POSSIBLE_NAMES", "Lon*",
"Y_POSSIBLE_NAMES", "Lat*",
"KEEP_GEOM_COLUMNS", "NO"
};
using (var ds = Gdal.OpenEx(input, 4, null, openOptions, null))
{
if (ds == null)
{
throw new Exception("Can't open OGR dataset: " + input);
}
// var layer = ds.GetLayerByIndex(0); <----- COMPILE ERROR
}
Any help is much appreciated.
I am no swig expert at all, but it looks like the vector (OGR) part of the Dataset is specifically NOT defined for C# in the current GDAL code
I was facing similar issues with C++, trying to switch from ogr2ogr CLI to GDAL C++. Maybe this will help someone.
I had to format my options array differently to get it to work :
const char *optionsArray[5] = {
"X_POSSIBLE_NAMES=lon*",
"Y_POSSIBLE_NAMES=lat*",
"Z_POSSIBLE_NAMES=alt*",
"KEEP_GEOM_COLUMNS=NO",
NULL
};
In C++ I have to add the ending NULL as stated by GDALOpenEx documentation.
I try to write a sowftware so the production can easily confirm the material items.
Now when I want to get a production order by a key, it can't find a PO.
If I do the same thing with business partner, it works.
We use the PPS One addon for the SAP B1, so is there the problem? Is it not possible to access the data from this addon or what have I to change?
SAPbobsCOM.BusinessPartners vBP = connection.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
SAPbobsCOM.ProductionOrders vPO = connection.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders);
if(vBP.GetByKey("L22437"))
{
WriteLogLine("Name: " + vBP.CardName); // Works, i get the Name!
}
else { WriteLogLine("No matching customer record was found!"); }
if (vPO.GetByKey(anyKey)) // tried a lot of keys, no one worked
{
WriteLogLine(vPO.GetAsXML());
}
else { WriteLogLine("No matching production order record was found!"); }
There is also a weird thing, in the SAP GUI the po are displayed as work orders, but the coresponding table in the db is #PPSONE_PRDORDERS. But it works neither if I change from SAPbobsCOM.ProductionOrders to SAPbobsCOM.WorkOrders.
If I understood, it doesn't matter what the addon does if at least it creates a record in the PO table, if you want to find the records of PO's you have to query the OWOR table, the field to use in the GeyByKey method of PO is the OWOR.DocEntry.
If this is a UserTable with no Object ou can use the object UserTable
UserTable oUst = (UserTable)oCompany.UserTables.Item(YOURTABLE);
if oUst.GetByKey("1") ....
If it is a UserTable with Object you have to look for GenericServices
Dim oGeneralService As SAPbobsCOM.GeneralService
Dim oGeneralData As SAPbobsCOM.GeneralData
Dim oGeneralParams As SAPbobsCOM.GeneralDataParams
Dim sCmp As SAPbobsCOM.CompanyService
sCmp = oCompany.GetCompanyService
'Get a handle to the SM_MOR UDO
oGeneralService = sCmp.GetGeneralService("SM_MOR")
'Get UDO record
oGeneralParams = oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)
oGeneralParams.SetProperty("DocEntry", "2")
oGeneralData = oGeneralService.GetByParams(oGeneralParams)
There is a SDK from PPS One you can use. Refere to: C:\Program Files\SAP\SAP Business One\AddOns\PPSOne\PPSOne\X64Client\PPSOne_PPSOneSDK.dll. I don't test it.
I'm stuck with how to check if a table already exists.
I have been searching but like many times before I can't find good examples.
The ones I find on SQLite don't work with the PCL version. I can't understand why though, so if anyone has a good site where to go please feel free to add them.
These are the ones I have used:
http://blogs.u2u.be/diederik/post/2015/09/08/Using-SQLite-on-the-Universal-Windows-Platform.aspx
https://code.msdn.microsoft.com/windowsapps/Implement-SQLite-Local-8b13a307#content
This is my code showing how I have tried to check it, but it only checks the path, which always exists. Not a smart solution when I thought about it.
private void LikeItButton_Click(object sender, RoutedEventArgs e)
{
var sqlpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Filmdb.sqlite");
using (SQLite.Net.SQLiteConnection conn =
new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath))
{
if (File.Exists(sqlpath))
{
AdMovieID();
}
else
{
conn.CreateTable<MovieID>();
AdMovieID();
}
}
}
You could execute a query:
SELECT name FROM sqlite_master WHERE type='table' AND name='MovieId';
by doing
var tableExistsQuery = "SELECT name FROM sqlite_master WHERE type='table' AND name='MovieId';"
var result = conn.ExecuteScalar<string>(tableExistsQuery);
I'm trying to make a simple statistical tool with using R and R.NET on C#.NET environment. I'm having problems getting data from R. Code is below
bool initResult = REngine.SetDllDirectory(rPackagePath);
if (!initResult)
throw new Exception(#"R Initialization Failed");
engine = REngine.CreateInstance("tsEngine");
if (engine == null)
throw new Exception(#"REngine Creation Failed");
engine.Evaluate("testData<-read.table('test_data.txt',sep='', header=TRUE)");
I'm trying to get the imported data and show it in a gridview
DataFrame dataset = engine.EagerEvaluate("testData").AsDataFrame();
I get ParseException at this point.
What can be the problem?
Thanks a lot.
First, change the last line to:
DataFrame testData = engine.Evaluate("testData<-read.table('test_data.txt',sep='', header=TRUE)").AsDataFrame();
Then add the following line:
engine.SetSymbol("testData",testData);
With the SetSymbol your engine will recognize the variable "testData" if you use it again.