2
private DataTable GetTableN(string sql, string[] pars)
{
NpgsqlCommand zapytanie = new NpgsqlCommand(sql, connn, trann);
NpgsqlDataAdapter da = new NpgsqlDataAdapter();
DataSet ds = new DataSet();
try
{
if (pars != null)
{
for (int i = 0; i < pars.Length; i++)
{
zapytanie.Parameters.AddWithValue("@param" + i, pars[i]);
}
}
connn.Open();
da.SelectCommand = zapytanie;
da.Fill(ds);
return ds.Tables[0];
}
catch (NpgsqlException e)
{
throw (new SqlException(e.Message.ToString()));
}
finally
{
connn.Close();
zapytanie.Dispose();
da.Dispose();
ds.Dispose();
}
}
は、今私が代わりにODBCを使用したが、全く同様の方法を持っている必要があります。私は、私はコードの重複を避けるために、これをマージし、唯一持っているかどうOdbcException
にOdbcDataAdapter
- NpgsqlCommandこれらの変更を加える必要があると思います1つの方法?
応じブール、useODBCか何か、およびコードをお持ちですか? – BugFinder
[OK]を、どのように私は、try finallyブロックの重複を避けるのですか? – jankes
アイブ氏はNGpgsqlコマンドを使用していないが、彼らはあなたがポイントの後にコードの重複を防ぐことはできません – BugFinder