C # how to connect to the sybase database using ODBC

Source: Internet
Author: User
Tags sybase sybase client sybase database

1. Install the Sybase client on the server and configure dsedit, for example:

2. Configure the ODBC system DSN, for example:

3. source code example:

The following is a code snippet:

 

The following is a code snippet:

Public xmldocument riverxml () // log Library
{
// Define the ODBC Data Source of the log Library
String strodbcconnection_logdb = "driver = {sybase system 11}; srvr = jdtmdb; uid = sa; Pwd =; DB =Logdb"; // Logdb is the database name

Odbcconnection ologconn;
Odbccommand ologcmd;
Xmldocument Doc;
Xmltextwriter xtw;
String lchtml;

String strdbreturnstring;
Odbcdatareader mylogdatareader = NULL;
String stcd;
String stna = "";
String strsql;
Strsql = "select * From TV _river_t order by ymdhm DESC ";

// St_dam_r
Strdbreturnstring = "";
Ologconn = new odbcconnection (strodbcconnection_logdb );
Ologcmd = new odbccommand (strsql, ologconn );
Ologconn. open ();
Mylogdatareader = ologcmd. executereader (commandbehavior. closeconnection );
While (mylogdatareader. Read ())
{
Stcd = mylogdatareader ["stcd"]. tostring ();
If (stcd = "53049") stna = "Shao Bo water station ";
If (stcd = "53071") stna = "Xinghua ";
Strdbreturnstring + =
"<Rows>" +
"<Cols>" + stcd + "</Cols>" +
"<Cols>" + stna + "</Cols>" +
"<Cols>" + datetime. parse (mylogdatareader ["ymdhm"]. tostring ()). tostring ("yyyy-mm-dd hh: mm") + "</Cols>" +
"<Cols>" + mylogdatareader ["ZR"]. tostring () + "</Cols>" +
"<Cols>" + mylogdatareader ["Q"]. tostring () + "</Cols>" +
"<Cols>" + mylogdatareader ["xsa"]. tostring () + "</Cols>" +
"<Cols>" + mylogdatareader ["zrtend"]. tostring () + "</Cols>" +
"<Cols>" + mylogdatareader ["qmes"]. tostring () + "</Cols>" +
"</Rows> ";
Stna = "";
}
Mylogdatareader. Close ();
Ologconn. Close ();

//... The following section is omitted...

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.