3

如何使用c#通过odbc执行存储过程?

我想在没有 sql 注入风险的情况下执行它,我该怎么做?

4

1 回答 1

7
using (OdbcConnection connection = new OdbcConnection(connectionString))
using (OdbcCommand command = connection.CreateCommand())
{
    command.CommandText = commandText //your store procedure name;
    command.CommandType = CommandType.StoredProcedure;

    command.Paremeters.Add("@yourParameter", OdbcType.NChar, 50).Value = yourParameter

    DataTable dataTable = new DataTable();

    connection.Open();    
    using (OdbcDataAdapter adapter = new OdbcDataAdapter(command))
    {
        adapter.Fill(dataTable);
    }
}
于 2012-05-29T08:23:18.720 回答