如何使用c#?
通过odbc执行存储过程我想在没有sql注入风险的情况下执行它,我该怎么办?
答案 0 :(得分: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);
}
}