string strSql="Select * from test where id=@id"; DynamicParameters parameters = new DynamicParameters(); parameters.Add("@id", 12); string connectString="......." DataTable table = new DataTable("result"); using (SqlConnection sqlConnection = new SqlConnection(connectString)) { sqlConnection.Open(); var reader=sqlConnection.ExecuteReader(strSql,parameters); table.Load(reader); }
注意不要使用SqlParameter数组方式