2007年8月21日星期二

.NET ODBC链接Postgre

有报道说C#.NET 速成版不支持远程链接数据库,今天特地试了一下,用ODBC链接远端Postgre数据库
结果还是可以操作数据库的,其它限制我就不太关心了
说明可以使用速成版做一些数据库相关工具。


附代码:
string strCon = "DRIVER={PostgreSQL};DATABASE=demo;SERVER=192.168.0.*;PORT=5432;UID=**;PWD=**;";
OdbcConnection myConn = new OdbcConnection(strCon);
string strCom = " SELECT ***name FROM tbl_**** ";
OdbcCommand aCommand = new OdbcCommand(strCom, myConn);
try
{
myConn.Open();
OdbcDataReader aReader = aCommand.ExecuteReader();
while (aReader.Read())
{
checkedListBox1.Items.Add(aReader.GetString(0));
}
aReader.Close();
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

没有评论: