DataObject が機能していることが前提です。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SQLCA.DBMS = "ODBC" | |
SQLCA.AutoCommit = False | |
SQLCA.DBParm = "ConnectString='DSN=<server name>;UID=<user name>;PWD=<password>'" | |
CONNECT; | |
If SQLCA.SQLCode=-1 Then | |
MessageBox("Error","Database connection error") | |
HALT CLOSE | |
End If | |
dw_zip_code.SetTransObject( SQLCA ) | |
string zip | |
zip=sle_zip_code.Text | |
dw_zip_code.Retrieve(zip) | |
DISCONNECT; |
C# でいうと以下のようなコードとなります。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (OdbcConnection connection = new OdbcConnection(Properties.Resources.DatabaseConnectionParam)) | |
{ | |
try | |
{ | |
string zip = "55555"; | |
if(0<args.Length) | |
zip=args[0]; | |
connection.Open(); | |
string sql = "Select * from zipcode_usa where zip_code='"+zip+"';"; | |
OdbcDataAdapter adapter = new OdbcDataAdapter(sql, connection); | |
DataSet dataSet = new DataSet(); | |
adapter.Fill(dataSet); | |
DataTable table = dataSet.Tables[0]; | |
for (int i = 0; i < table.Columns.Count; i++) | |
{ | |
Console.Write(table.Columns[i].ToString()); | |
Console.Write(": "); | |
Console.WriteLine(table.Rows[0][i]); | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} |