473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

C# and ODBC?

joe
I'm pretty new to C# so forgive me if I missed something obvious. I'm
trying to find out if C# .NET can be used to access something other
than SQL Server, using ODBC. I haven't seen anything that talks about
ODBC in the book I have or from looking around on Microsoft.com.

If someone could point me to some documentation about this I'd
appreciate it.

Joe
--
It was impossible to get a conversation going;
everybody was talking too much.
- Yogi Berra
Nov 17 '05 #1
5 1851
Hi,

You can also use OLEDB, however the ODBC provider can be used. For the most
part you should first determine if there is not
a native managed provider for your target database if there is use that. If
not then try for an OLEDB provider and lastly go the ODBC route.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
<jo*@invalid.address> wrote in message
news:m3************@invalid.address...
I'm pretty new to C# so forgive me if I missed something obvious. I'm
trying to find out if C# .NET can be used to access something other
than SQL Server, using ODBC. I haven't seen anything that talks about
ODBC in the book I have or from looking around on Microsoft.com.

If someone could point me to some documentation about this I'd
appreciate it.

Joe
--
It was impossible to get a conversation going;
everybody was talking too much.
- Yogi Berra

Nov 17 '05 #2
joe
"Chris Taylor" <ch*************@hotmail.com> writes:
You can also use OLEDB, however the ODBC provider can be used. For
the most part you should first determine if there is not a native
managed provider for your target database if there is use that. If
not then try for an OLEDB provider and lastly go the ODBC route.


Thanks, do you know of a web page that gives more details about how to
do this? I'm working through a book called "Microsoft Visual C# .NET
Step by Step" but it doesn't go into anything but SQL Server.

Joe
--
It was impossible to get a conversation going;
everybody was talking too much.
- Yogi Berra
Nov 17 '05 #3
joe
jo*@invalid.address writes:
"Chris Taylor" <ch*************@hotmail.com> writes:
You can also use OLEDB, however the ODBC provider can be used. For
the most part you should first determine if there is not a native
managed provider for your target database if there is use that. If
not then try for an OLEDB provider and lastly go the ODBC route.


Thanks, do you know of a web page that gives more details about how to
do this? I'm working through a book called "Microsoft Visual C# .NET
Step by Step" but it doesn't go into anything but SQL Server.


Ahh, never mind. I found some stuff on the MSDN web site.

Thanks

Joe
--
It was impossible to get a conversation going;
everybody was talking too much.
- Yogi Berra
Nov 17 '05 #4
It can probably be simpler but here is what I and my colleagues did on
a small school project.
The odbc connection connected to a PostgreSql database.
Add the following "using" statement to the top of the cs page:

using System.Data.Odbc;

Then, here is a routine that was used to select data from a table and
bind it to a drop down box on the form.
private void InitWardDropDown()
{
OdbcConnection cn;
string sConnString
=@"Protocol=6.4;LFConversion=1;Ksqo=1;UnknownSizes =0;Debug=0;UseServerSidePrepare=0;Parse=0;SERVER=s erver8.cs.uofs.edu;ByteaAsLongVarBinary=0;TextAsLo ngVarchar=1;DRIVER=PostgreSQL;ReadOnly=0;FakeOidIn dex=0;ConnSettings=;MaxLongVarcharSize=8190;MaxVar charSize=254;Socket=4096;TrueIsMinus1=0;DisallowPr emature=0;DATABASE=se521grp3;Optimizer=1;UID=se521 grp3;ShowOidColumn=0;UseDeclareFetch=0;CancelAsFre eStmt=0;BI=0;CommLog=0;Fetch=100;UpdatableCursors= 0;ExtraSysTablePrefixes=dd_;UnknownsAsLongVarchar= 0;RowVersioning=0;PORT=5432;BoolsAsChar=1;ShowSyst emTables=0";
cn = new OdbcConnection(sConnString);
cn.Open();

// The following select union puts an empty record at the
beginning of the
//return data. This makes the first item inthe drop down list
appear empty.
string sSql = "select '' as name from ward UNION select name
from ward order by name";
//Set up the data adapter
OdbcDataAdapter da = new OdbcDataAdapter();
da.TableMappings.Add("Table", "ward");
OdbcCommand cm = new OdbcCommand(sSql,cn);
cm.CommandType = CommandType.Text;
da.SelectCommand = cm;
da.SelectCommand.CommandText = sSql;
da.SelectCommand.Connection = cn;

//I think Dataset name here has to match DA mapping above.
DataSet ds = new DataSet("ward");
//tell the data adapter to fill the dataset
da.Fill(ds);

//The following 4 lines bind the dataset to the drop down
//list, giving it its values.
//ddlWard is the drop down list on the html form
ddlWard.DataSource=ds;
ddlWard.DataMember = ds.Tables["ward"].ToString();
ddlWard.DataValueField = "name";
ddlWard.DataBind();

//release the resources
ds.Dispose();
da.Dispose();
cn.Close();
}

Hope it is more helpful than confusing.
Jeff

On 25 Sep 2005 12:05:56 -0500, jo*@invalid.address wrote:
I'm pretty new to C# so forgive me if I missed something obvious. I'm
trying to find out if C# .NET can be used to access something other
than SQL Server, using ODBC. I haven't seen anything that talks about
ODBC in the book I have or from looking around on Microsoft.com.

If someone could point me to some documentation about this I'd
appreciate it.

Joe


Nov 17 '05 #5
joe
Jeff <je*******@hotmail.com> writes:
It can probably be simpler but here is what I and my colleagues did on
a small school project.


Thanks, postgres was what I had in mind as well. Appreciate it.

Joe
--
It was impossible to get a conversation going;
everybody was talking too much.
- Yogi Berra
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marco Aschwanden | last post by:
Hi - Win2000 - Python 2.3.3 - py2exe 0.5.0 - eGenix Comercial & Base Package I am developing an app using mxODBC. On the home page they say ...
11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client component. Thanks. Kong ----- From: Kong...
6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
4
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript...
4
by: Andreas Lauffer | last post by:
Can anyone tell me advantages / disadvantages of DataDirect Server Wire ODBC-driver? Any experiences? What about redistribution? Andreas Lauffer, easySoft. GmbH, Germany
3
by: Lauren Quantrell | last post by:
Maybe a dumb question - I'm new to ODBC. How do I install an Access ..mde file on a user's workstation and create the ODBC connection to the backend SQL Server database without having to go through...
5
by: Alec | last post by:
Hi All, I am currently trying to link in Access 97 to a table in a MSSQL 7 server. Initially the link is fine, however, when I close the access database and re-open it from the same network...
2
by: Crazy Cat | last post by:
Hi all, I am having trouble getting linked Oracle 9 server in MS SQL Server 2005 Express to work properly. My machine is running Windows XP. The Microsoft and Oracle OLE DB Providers have...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.