|
|
I'm struggling with understanding, what I think are difference between the Types used in .NET framework and the OLE DB Data Types used in Access, Excel, etc.
For example:
Type indicator OLE DB Name .Net Type Description
DBTYPE_UI8 BigInt Int64 64-bit signed integer
What's does Int64 map to in C#? Am I using the correct terminology?
It's difficult to look up an answer to a question when you don't know what something is called.
|
|
|
|
|
|
|
Well, I just spent the better part of the afternoon yesterday creating this chart myself. LOL
Can't seem to get past this. Everything I do is giving me an invalid cast exception.
I'm using GetOleDbSchemaTable ( OleDbSchemaGuid.Columns, ...)
I thought had a breakthrough, when I read that my cast was failing because it needed unboxed, so this one worked:
long ORDINAL_POSITION = (long)row.Field<Int64> ( "ORDINAL_POSITION" );
But the Data_Type is not working. The documentation says it's a
UInt16 which I should be able to cast like this:
ushort DATA_TYPE = (ushort)row.Field<UInt16> ( "DATA_TYPE" ); but that gives me the same invalid cast exception. I can't even be sure that the cast that is causing the exception is ushort and UInt16 because I'm not understanding where to look.
|
|
|
|
|
Presumably you verified that the exception is coming from that exact line.
Extract the column as a generic object and then print that out. That will tell you the exact data type.
If that doesn't help then post the output from the above along with the class cast exception text.
|
|
|
|
|
Thank you. I'm not far enough along to know how to do that just yet, but this is something I've been wanting to learn. It turns out that I was fist having cast issues because of db data type vs my C# data types did not always match appropriately, but there was also an issue with DBNull being returned in numeric types in SQLServer, which is not acceptable for C# value types.
The lack of surety in programming is part of the reason software is fragile.
|
|
|
|
|
You don't need the extra cast - the Field<T> method already returns the correct type. There's no boxing/unboxing involved.
long ORDINAL_POSITION = row.Field<Int64> ( "ORDINAL_POSITION" );
ushort DATA_TYPE = row.Field<UInt16> ( "DATA_TYPE" );
The C# types are just aliases for the .NET equivalents; so long === System.Int64 , etc.
I suspect the documentation is probably wrong, and the DATA_TYPE column is most likely an Int32 , which can then be cast to an OleDbType value. Check the value returned by table.Columns["DATA_TYPE"].DataType to see what it's defined as.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm not sure I understand that because I I really struggled with trying to get the Int64 to cast to long.
It *may* have been that I was getting DBNull back for value types out of SQL Server, which causes an exception. I left the explicit cases in my code just because I'm afraid of breaking it and I have moved on to something else, finally.
I appreciate your help and will exclude the explicit casts the next time I need to get the values form a database in some code that I feel more comfortable with. This code includes a ton of other C# constructs that are new to me, which lead to a pretty terrible debugging experience.
The lack of surety in programming is part of the reason software is fragile.
|
|
|
|
|
The Problem:
Parent & child relationship currently captured in tblCGs and tbcs tables. The MasterClient are held in tblCGs table while Children are stored in tblCs tables using tblCGs. GroupMasterCustKey as key and CustomerKey as Child key.
• Currently a tblCGs table allows the linking of Parent using (GroupMasterCustKey) to child tblcs - (CustomerKey) table which may or may not exist.
AssociatedClient Field in the tblcs table: These are related clients without any hierarchical relationship.
• Currently the AssociatedClient on the tblCs table is too limiting varchar(20) and
can have implications or cause issues.
Proposed Solution:
• To Implement a new table structure where individual rows such as MIND227 - MIND227(customer ranges) are retrieved from the table rather than IND227 - IND229
• Move the Associatedclients Field in tblcs into a separate table with the following fields (ID, ClientID1, ClientID2..... , ClientRelationshipReasonID, and CreatedDate)
Please see the sample code below
IF OBJECT_ID('tempdb..#tblCGs') IS NOT NULL DROP TABLE #tblCGs
IF OBJECT_ID('tempdb..#tblCs') IS NOT NULL DROP TABLE #tblCs
--Create ClientGroups table.
CREATE TABLE #tblCGs
(
[GroupID] int NOT NULL, ---- IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[GroupMasterCustKey] varchar(100) NOT NULL, ---[MasterCAN]
[GroupFromCustKey] varchar(100) NOT NULL, --- CONSTRAINT [DF_tblCGs_GroupFromCustKey] DEFAULT (' '),
[GroupToCustKey] varchar(100) NOT NULL -- CONSTRAINT [DF_tblCGs_GroupToCustKey] DEFAULT (' '),
)
-- Populate the table with values.
INSERT INTO #tblCGs VALUES
(988, N'MIN036', N'MIND227', N'MIND229')
, (668, N'08035635', N'31036422', N'31036422')
,(669, N'08035635', N'31035623', N'31035623')
-- Create Customer table.
CREATE TABLE #tblCs ---Customers
([CustomerID] int not null ------IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
,[CustomerKey] varchar(100) NOT NULL --- [ChildCAN]
,[CompanyName] varchar(300) NULL
,[AssociatedClient] varchar(20)
,[CreatedOn] Datetime
)
--Populate the table with values.
INSERT INTO #tblCs VALUES
(72894, N'MIND227', N'MIND Mind in Haringey', N'MIN036','2011-11-16 00:00:00.000')
,(93469, N'MIND228', N'Caerphilly Borough Mind', N'MIN036','2014-03-08 00:00:00.000')
,(98199, N'MIND229', N'Brecon and District Mind', N'MIN036,BDC004,POW044','2014-11-26 00:00:00.000')
,(61705, N'31036422', N'Revive', N'Null','2010-04-01 09:13:10.550')
,(61729, N'31035623', N'Jysk Ltd', N'Null','2010-04-01 12:56:16.837')
--- Current Queries
SELECT *
FROM #tblCGs AS CG
INNER JOIN #tblCs AS C
ON C.CustomerKey >= CG.GroupFromCustKey
AND C.CustomerKey <= CG.GroupToCustKey
The desired output should like this and not output of the above query
ID ClientID1 ClientID2 ReasonTypeID
1 201 301 1
2 201 302 1
3 201 303 1
4 303 401 1
5 601 701 3
Thanks for your help
|
|
|
|
|
|
Hi all,
I have one task ,
To convert an Excel file to CSV and then move that data from CSV to oracle database.
EXCEL FILE HAS :3 COLUMNS
NAME,CITY,STATE .
my requirement is I need to convert from excel to csv and csv to oracle datatable I have to do in backend.
asked me to use sqlloader.
earlier I haven't worked on this type of ticket.
can you please give me an idea .
I have to do in backend not in .net application.
I am using ORACLE(TOAD)
What I have tried:
Hi all,
I have one task ,
To convert an Excel file to CSV and then move that data from CSV to oracle database.
EXCEL FILE HAS :3 COLUMNS
NAME,CITY,STATE .
my requirement is I need to convert from excel to csv and csv to oracle datatable I have to do sqlloader .
earlier I haven't worked on this type of ticket.
can you please give me an idea .
I have to do in backend not in .net application.
I am using PLSQL(TOAD)
|
|
|
|
|
If it is one time...
1. You can save the file as CSV. Do a "save as" and then pick the 'type' via the drop down.
2. Then as noted you can use sqlloader.
If you must automate this to do it over and over then there are other problems you did not touch on like how you know there is a new file and how to recognize an update versus new.
But at any rate it is possible to read an excel file via an "ODBC" driver. I believe this is still possible, once you track down the driver. This would with very simple Excel files.
|
|
|
|
|
Why do you need to convert to CSV, why not just read the data from the Excel file and send it direct to the database? And why have you posted the question twice with slightly different details?
|
|
|
|
|
Hi All,
I have a new product must be cloud over an internet and we need to choose the best database for this issue from the pricing and performance issues.
we need to know the best for this, is it the Microsoft SQL Server or the PostgreSQL.
(SQL Server VS PostgreSQL).
also I need the best tutorial and videos about the PostgreSQL database.
Please Help me ASAP.
Thank You All
|
|
|
|
|
Performance from any database will vary greatly based on what the actual use case is. If you're looking to warehouse data the "best" product will be very different than if you need a speedy cache, for instance.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Based on the requirements you posted (none) the best one is going to be the one that your or the other developers have the most experience with.
|
|
|
|
|
Hi
I want write a code that overwrite from a folder of DB to a other folder and this code run as windows services,How do I write this code?
Thanks Very Much
Marzi
|
|
|
|
|
I would start with writing a code that runs as windows service and can do what you need.
|
|
|
|
|
While exchanging referrals and asked to write bitcoint to where money was transferred what do i write?am using my name but am not its not found on database please help
|
|
|
|
|
What are you talking about?
|
|
|
|
|
Am an online worker and i need to buy some referrals since have attracted non but am unable since i dont know what to fill when requested to state a bitcoin to where money was transferred
|
|
|
|
|
This site is not associated with such things: they are a deliberate distortion of statistics designed to fool users into thinking a site is more popular than it is.
Go to google, and try there: Buying of referrals - Google Search[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
For many years, I have been successfully using MS Access VBA to import data from a Sybase ASE server through direct queries. Several years ago, it was necessary to locate and install new drivers when I upgraded from XP to Win7 64-bit. All was working well until I got a new Win10 PC. I fought with installing the same drivers I used with the Win7 machine but was finally able to make a successful connection. The recordsets that are returned contain empty character fields. Numeric and date fields display fine.
For example,
SELECT 123 FROM someTable Returns: 123
SELECT '123' FROM someTable Returns:
I tried different values for the CharacterSet parameter in the connection string but it made no difference. I also googled... There was some information regarding empty strings for formatting purposes but none that I found that would explain the above results.I can't figure out why only char fields are affected. I would expect all or nothing if it were a driver issue but the same drivers work in Win7.
Any thoughts??
|
|
|
|
|
Presuming you are not hiding/eating errors then it has nothing to do with connections nor general calling semantics.
However it very likely has to do with HOW you are calling it which you did not specify.
But I will note that in the first case I would expect a caller to be defined to expect a numeric value.
While the second would require a caller to expect a textual value and probably a 'CHAR' type with a specific size (3 or greater) specified.
|
|
|
|