1.在伺服器上安裝Sybase用戶端,配置Dsedit,如:
2.配置ODBC的系統DSN,如:
3.原始碼樣本:
以下是程式碼片段:
以下是程式碼片段: public XmlDocument RiverXml() //Log庫 { //定義LOG庫的ODBC資料來源 string strODBCConnection_LogDB = "Driver={SYBASE SYSTEM 11};Srvr=jdtmdb;Uid=sa;Pwd=;DB=logdb"; // logdb 是資料庫名稱 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 = "邵伯水位站"; if (STCD == "53071") STNA = "興化"; 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(); // .... 以下部分略... } |
|
|